php - mod_rewrite changing address bar for no reason -
i have .htaccess file , when ever type www.example.com/demo/index.php keeps redirected me in loop. i'm confused why happening.
# not remove line, otherwise mod_rewrite rules stop working rewritebase / options +multiviews addhandler application/x-httpd-php .css addhandler application/x-httpd-php .js rewriteengine on #nc not case sensitive #l last rule don't process futher #r 301 changes url want rewriterule ^demo(.*)$ finished$1 [nc] rewritecond %{request_uri} ^/finished/.*$ rewriterule ^finished/(.*)$ demo/$1 [nc,r=301,l]
i can see rewrite loop happening if doing:
http://mydomain/demo/rewrite.cgi
because rewritten first rule to
http://mydomain/finished/rewrite.cgi
and matches rewrite condition of second rewrite rule , gets rewritten to:
http://mydomain/demo/rewrite.cgi
and loop starts.
there's 2 fixes here either a) add l
flag first rewrite rule (makes last rewrite happen) or b) if demo rewrite not followed slash i'd make implicit:
rewriterule ^demo([^/]+)$ finished$1 [nc]
the other option if that's not cause, turn on rewrite rule logging , @ being done create loop:
rewritelog /path/to/rewrite.log rewriteloglevel 3
Comments
Post a Comment