Htaccess重定向到https

时间:2012-10-27 16:33:24

标签: php apache .htaccess https

我正在使用以下httaccess内容,强制重写网址以使用https而不是http

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L]

但它总是得到, 页面未正确重定向

Firefox has detected that the server is redirecting the request for this address
in a way that will never complete.     
This problem can sometimes be caused by disabling or refusing to accept
cookies.

我已经使用了很多其他解决方案,但总是得到这个......

1 个答案:

答案 0 :(得分:1)

请尝试以下代码.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

#uncomment the below two line if you need to append www
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]