我最近将 SSL 添加到我的 wordpress 网站,现在如果有些人访问我的 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.
我做错了什么?
最佳答案
这是您应该用于执行 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
关于wordpress - htaccess wordpress 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15377401/