【发布时间】:2018-02-15 16:55:43
【问题描述】:
情况如下:
- 旧域 (none-SSL) 我们称之为“no-ssldomain.com”
- 新域(使用 SSL)我们称之为“ssldomain.com”
两个域都指向同一个服务器。所以使用这两个域都可以。
No-ssldomain.com 已经运行了 7 年,但由于我所追求的域名现在可用,我使用 SSL 注册了它并试图永久迁移到它。
它在 Wordpress 上运行,所有永久链接都有效,所有重定向都有效。旧的 no-ssldomain.com 嵌套链接完美地重定向到新的 ssldomain.com。所以没有谷歌处罚。不错。
我当前的配置做了什么(使用分号,因为我不能发布超过 2 个链接):
- 如果您输入:http;//no-ssldomain.com > 重定向到 > https;//ssldomain.com
- 如果您输入:https;//no-ssldomain.com > 重定向到 > https;//ssldomain.com 李>
- 如果您输入:http;//no-ssldomain.com/xx/xx/xx > 重定向到 > https;//ssldomain.com /xx/xx/xx
但发现 1 个烦人的问题。
如果您输入:https;//no-ssldomain.com/xx/,它将使用 no-ssldomain.com 打开网页并显示不安全警告。它不会重定向到新的 ssldomain.com。那么我怎样才能正确地重定向它呢?
这是我的服务器配置:
server {
listen 80;
server_name no-ssldomain.com;
location / {
rewrite "/([0-9]{4})/([0-9]{2})/(.*)" http://$host/$3 permanent;
}
if ($host = "no-ssldomain.com") {
return 301 https://ssldomain.com$request_uri;
}
}
server {
listen 80;
listen 443;
ssl on;
ssl_certificate /xxx/xxx/ssldomain_com.chained.crt;
ssl_certificate_key /xxx/xxx/server.key;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php;
server_name ssldomain.com;
location /wp-admin {
index index.php;
}
location / {
index index.php;
rewrite "/([0-9]{4})/([0-9]{2})/(.*)" https://ssldomain.com/$3 permanent;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
【问题讨论】: