重定向到https几乎工作,但不完全

时间:2012-07-26 18:20:30

标签: .htaccess redirect https

我有一个网站,我希望有以下重定向:

1. http://mysite.net     => https://www.mysite.com
2. http://www.mysite.net => https://www.mysite.com
3. http://mysite.com     => https://www.mysite.com
4. http://www.mysite.com => https://www.mysite.com

我已经达到了1,2和3,但由于“重定向太多”,我在第4次遇到麻烦。这是我的htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?mysite\.net$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]

# Use PHP5.3 as default
AddHandler application/x-httpd-php53 .php

# Send all traffic of main domain to subdirectory

RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/sites/mysite.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sites/mysite.com/$1 [L]

RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ sites/mysite.com/index.php [L]

任何帮助?

1 个答案:

答案 0 :(得分:0)

神奇的解决方案是:

RewriteEngine on

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} ^(www.)?mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www.)?mysite\.net$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]

# Use PHP5.3 as default
AddHandler application/x-httpd-php53 .php

# Send all traffic of main domain to subdirectory

RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/sites/mysite.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sites/mysite.com/$1 [L]

RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ sites/mysite.com/index.php [L]