2013-03-13 194 views
2

我最近增加了SSL到我的WordPress站点,现在如果有人去我的http站点,我想重定向他们到我的https站点。我曾尝试下面的以下内容:htaccess wordpress 301重定向

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{HTTPS} !=on 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 

但得到这个错误

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects. 

我在做什么错?

回答

1

下面是你应该强制执行HTTPS使用代码:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

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

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
0

试试这个:

RewriteEngine on 

RewriteCond %{SERVER_PORT} 80 

RewriteRule ^(.*)$ https://{SERVER_NAME}/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^www\.(.*) 

RewriteRule ^(.*)$ https://{SERVER_NAME}/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^http://\.(.*) 

RewriteRule ^(.*)$ https://{SERVER_NAME}/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} -s [OR] 

RewriteCond %{REQUEST_FILENAME} -l [OR] 

RewriteCond %{REQUEST_FILENAME} -d 

RewriteRule ^.*$ - [NC,L] 

RewriteRule ^.*$ /index.php [NC,L]