Nginx / .htacces重定向无法正常工作

时间:2018-07-03 20:35:44

标签: wordpress .htaccess nginx

我无法弄清楚我的Nginx Virtualhost或/和Wordpress重写规则出了什么问题,它如下:

http://example.com-> https://www.example.com有效;

http://www.example.com-> https://www.example.com有效;

https://example.com-> https://www.example.com根本不起作用!

我尝试了尽可能多的挖掘日志。

我的Nginx虚拟主机:

server {

# Uncomment the following line for domain mapping
# listen 443;

server_name example.com;
return 301 $scheme://www.example.com$request_uri;

root /var/www/example.com/htdocs;

index index.php index.html index.htm;

include  common/wpsc.conf;     include common/wpsubdir.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/example.com/conf/nginx/*.conf;



}
server {
# Uncomment the following line for domain mapping
# listen 443;

server_name www.example.com;

root /var/www/example.com/htdocs;

index index.php index.html index.htm;

include  common/wpsc.conf;     include common/wpsubdir.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/example.com/conf/nginx/*.conf;
}

我的htaccess重写器:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

我使用https://easyengine.io/安装/配置所有内容,并从Cpanel迁移了我的WordPress网站。

我可能会错过什么?

1 个答案:

答案 0 :(得分:0)

首先,Nginx不支持.htaccess文件。

第二,很难确定为什么它不起作用,但这是我要检查的内容:

  • example.com是否具有SSL证书?如果发生重定向,通常不会发生 SSL验证失败。
  • WordPress siteurlhome是否设置为https://www.example.com
  • nginx错误日志中是否显示任何错误?