开发者

mod_rewrite and .htaccess - stop rewrite if script/file exists

开发者 https://www.devze.com 2023-02-17 00:15 出处:网络
This is my htaccess: RewriteEngine On #开发者_开发技巧 Stop if it\'s a request to an existing file.

This is my htaccess:

RewriteEngine On



#开发者_开发技巧 Stop if it's 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 forwards everything to my index.php script! It dosen't stop if a script exists. Anyone have any idea why this isn't working? I've looked everywhere, but I don't really understand mod_rewrite (as much as I thought!).

The problem has come about because I've put in <script> tags which point to .js files in my web directory which are then forwarded to the index.php script. The web developer toolbar tells me this. :) And clicking links to the js files in firefox's view source window also shows the index.php output.

thank you.


This is because after processing a rewrite rule the whole process restarts with the new url. The processing of an url can go thru the rules over and over again each time with the changed URL, until there is no more change (no applying rules found).

You need this:

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

Don't think of the rules as a program, they are rules which can overlap and must be as specific as possible with each one.


I guess you should add [OR] after the first condition like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消