I have an .htaccess file and when ever i type www.example.com/demo/index.php it keeps redirected me in a loop. I'm really confused as to why this is happening.
# Do not remove this line, otherwise mod_rewrite rules will 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 the url to what you want
RewriteRule ^demo(.*)$ finished$1 [NC]
RewriteCond %{REQUEST_URI} ^/finished/.*$
RewriteRule ^finished/(.*)$ demo/$1 [NC,R=301,L]
I can see the rewrite loop happening if you are doing:
http://mydomain/demo/rewrite.cgi
because that will get rewritten by the first rule to
http://mydomain/finished/rewrite.cgi
And then that matches the rewrite condition of the second rewrite rule and gets rewritten to:
http://mydomain/demo/rewrite.cgi
and your loop starts.
There's probably two fixes here either a) add the L
flag to the first rewrite rule (makes it the last rewrite that will happen) or b) if your demo rewrite not followed by a slash I'd make that implicit:
RewriteRule ^demo([^/]+)$ finished$1 [NC]
The other option if that's not the cause, it to turn on rewrite rule logging and look at what is being done to create the loop:
RewriteLog /path/to/rewrite.log
RewriteLogLevel 3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.