我刚刚在我的Wordpress网站上安装了SSL,现在正尝试将整个网站重定向到https。
似乎在Chrome,IE,Firefox,手机等方面对我有用,但是,如果我通过各种在线状态检查程序或网站速度检查程序运行我的网站,他们都会返回错误并说我的网站是无法访问。例如:
tools.pingdom.com - 说我的网站有一个重定向循环
isitdownrightnow.com - 说我的网站已关闭
sitestatus.net - 说我的网站有301移动永久性错误
等等。所以,有些事情显然是错误的。这是我的.htaccess代码:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteRule ^(.*) https://www.low-caloriediet.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Redirect 301 /guest-post-guidelines https://www.low-caloriediet.com/contact
Redirect 301 /breakfasts-food https://www.low-caloriediet.com/food/breakfasts-food
Redirect 301 /lunch-dinners https://www.low-caloriediet.com/food/lunch-dinners
Redirect 301 /appetizers https://www.low-caloriediet.com/food/appetizers
Redirect 301 /snacks https://www.low-caloriediet.com/food/snacks
Redirect 301 /desserts-food https://www.low-caloriediet.com/food/desserts-food
Redirect 301 /low-calorie-drinks https://www.low-caloriediet.com/food/low-calorie-drinks
Redirect 301 /extras https://www.low-caloriediet.com/food/extras
Redirect 301 /calorie-granola https://www.low-caloriediet.com/food/calorie-granola
Redirect 301 /calorie-pasta https://www.low-caloriediet.com/food/calorie-pasta
Redirect 301 /calorie-chocolate https://www.low-caloriediet.com/food/calorie-chocolate
Redirect 301 /calorie-cookies https://www.low-caloriediet.com/food/calorie-cookies
Redirect 301 /calorie-yogurt https://www.low-caloriediet.com/food/calorie-yogurt
Redirect 301 /calorie-soup https://www.low-caloriediet.com/food/calorie-soup
Redirect 301 /calorie-muffins https://www.low-caloriediet.com/food/calorie-muffins
Redirect 301 /calorie-butter https://www.low-caloriediet.com/food/calorie-butter
Redirect 301 /calorie-pancakes https://www.low-caloriediet.com/food/calorie-pancakes
Redirect 301 /calorie-beer-alcohol https://www.low-caloriediet.com/food/calorie-beer-alcohol
Redirect 301 /calorie-oatmeal https://www.low-caloriediet.com/food/calorie-oatmeal
Redirect 301 /calorie-cereal https://www.low-caloriediet.com/food/calorie-cereal
Redirect 301 /calorie-bread https://www.low-caloriediet.com/food/calorie-bread
Redirect 301 /calorie-chips https://www.low-caloriediet.com/food/calorie-chips
Redirect 301 /calorie-crackers https://www.low-caloriediet.com/food/calorie-crackers
我只能假设这个有问题或者与此相冲突:
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteRule ^(.*) https://www.low-caloriediet.com/$1 [R=301,L]
因为如果我删除它,我可以访问我的网站tools.pingdom.com等。任何想法发生了什么?谢谢!
编辑:服务器是NGINX
答案 0 :(得分:0)
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这取自https://stackoverflow.com/a/13997498/3468562,已有这样的答案。 :)
答案 1 :(得分:0)
将WP规则更改为:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
确保您在WP永久链接设置中的主页和网站网址中有https
。