Redirect anything to a single php file with url rewriting
I'm trying to redirect anything to my index.php file to do myself the redirection.
If i use this:
#RewriteRule ^(.+)$ index.php?path=$1%{QUERY_STRING} [L]
but that's not working because it is "looping" on the rule.
This works :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}开发者_开发问答 !-f
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]
</IfModule>
but i want to redirect it even if it is an existing file or directory (i thing i will make specials routes for image, js and so on to redirect on them with php without loading any script.
In fact, if there were a "no-loop" flag, that would be fine.
Anybody knows the solution ?
Thanks
Here is one way to avoid looping:
RewriteRule ^(?!index\.php)(.+)$ index.php?path=$1%{QUERY_STRING} [L]
Uses negative lookahead (?!
) to see if the string includes index.php. If it doesn't, then carry on with the rewrite!
Replace the two Cond patterns with a check to see if you're hitting index.php:
RewriteCond %{REQUEST_URI} !^index.php
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]
that will redirect everything, EXCEPT the hits on index.php (to prevent loops).
精彩评论