我有一个Wordpress网站,该网站已进行了一些迁移。
目标是强制始终使用https
和www
进行重定向。
除http://www.caravelleconsulting.com以外,它可以正常工作,而无需https
重定向到http://www.caravelleconsulting.com
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Redirection to HTTPS AND WWW
# version 1
#RewriteCond %{HTTP_HOST} ^caravelleconsulting\.com$
#RewriteRule ^(.*)$ "https\:\/\/www\.caravelleconsulting\.com\/$1" [R=301,L]
# Version 2 - same result than the first version
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
# send to router
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
我找到了第三个解决方案here,但是当我用http://www.redirect-checker.org测试时,我得到了301 Moved Permanently循环。
我该如何解决?
答案 0 :(得分:0)
最后,我根据几个答案here
找到了解决方案.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
#avoid loop - (https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www)
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# send to router
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress