堆叠301重定向? .net到.com,www,https
问题描述:
我一直在努力让这个链工作: 我想指向example.net
到example.com
并指向一切到https://www.example.com
。堆叠301重定向? .net到.com,www,https
所以,我们有:example.net, www.example.net, example.com
和www.example.com
所有需要登陆https://www.example.com
。
我可以得到一切,但https
工作或https
只为.com
网站。
任何方式来设置它?
答
首先要example.net
重定向到example.com
,把下面的代码example.net
主根.htaccess
文件:
RewriteEngine On
RewriteRule (.*) https://www.example.com/$1 [R=301,NE,L]
然后在example.com
主根.htaccess文件把下面的代码:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
注意:清除您的浏览器缓存并进行测试。
+0
我很感激! – user116518
答
我终于能够得到这个工作:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC,OR]
RewriteCond %{HTTP_HOST} ^example.net [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.net [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#WordPress code
RewriteBase/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
欢迎堆栈溢出,请阅读[如何提问](https://stackoverflow.com/help/how-to (如何创建一个最小,完整和可验证的示例)(https://stackoverflow.com/help/mcve)。在提问之前,始终要具体并尽力而为。在这种情况下,我们想知道你作为主机使用什么? Apache,Ngix?或者你只是想使用DNS服务器? – Teocci