2014-01-23 128 views
1

下面是我的.htaccess文件。URL重定向导致循环

RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^([^\.]+)$ $1.php [L] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteRule ^axiom/?$ /axiom/publish.htm [L] 

这导致重定向循环。如果我注释掉

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

页面将load.I'm不知道在哪里我的错误,但我猜想它在这里的某个地方。

+0

什么是重写规则^的'目的$ HTTPS(*): //%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]'规则? – anubhava

+0

将http请求重定向到https。 –

回答

1

此规则重定向你要访问的URL相同 -

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

考虑您正在访问http://www.example.com/test/a.html。该重写规则匹配测试/ a.html和

REQUIEST_URI = test/a.html 
HTTP_HOST = www.exmpale.com 

所以,你重定向到https://www.example.com/test/a.html

那么你匹配相同条件再次被重定向到同一页面!

,如果你正试图从HTTP重定向到HTTPS,那么你需要添加另一个条件,以检查它是否来自HTTP或HTTPS

RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^([^\.]+)$ $1.php [L] 
RewriteRule ^axiom/?$ /axiom/publish.htm [L] 

RewriteCond %{HTTPS} ^off$ [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+0

这样做了,现在我完全理解发生了什么。感谢您的指导! –