htaccess wordpress 301重定向

时间:2013-03-13 05:00:02

标签: wordpress .htaccess redirect ssl

我最近在我的wordpress网站上添加了SSL,现在如果有人访问我的http网站,我想将它们重定向到我的https网站。我尝试过以下方法:

# 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.

我做错了什么?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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]