Mod_rewrite and .htaccess - stop rewriting if script / file exists

This is my htaccess:

RewriteEngine On



# Stop if it a request to an existing file.

RewriteCond %{REQUEST_FILENAME} -f [NC,OR]

RewriteCond %{REQUEST_FILENAME} -d [NC]

RewriteRule .* - [L]



# Redirect all requests to the index page

RewriteRule ^([^/])         /index.php          [L]

Now this redirects everything to my index.php script! It does not stop if a script exists. Does anyone know why this is not working? I searched everywhere, but I really don't understand mod_rewrite (as far as I thought!).

The problem arose because I added tags <script>that point to .js files in my web directory, which are then forwarded to the index.PHP script. This is evidenced by the web developer toolbar. :) And clicking links to js files in the firefox viewer window also shows the output of index.php.

thank.

+5
source share
2 answers

, URL-. URL- URL- , ( ).

:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)         /index.php          [L]

, - , .

+8

, [OR] :

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*) $1 [QSA,L]
+1

All Articles