【问题标题】:Stacking 301 redirects? .net to .com, www, https堆叠 301 重定向? .net 到 .com、www、https
【发布时间】:2017-10-10 00:27:34
【问题描述】:

我一直在努力让这条链正常工作: 我想将example.net 指向example.com,并将所有内容指向https://www.example.com

所以,我们有:example.net, www.example.net, example.comwww.example.com,它们都需要登陆 https://www.example.com

除了https 工作或https 仅用于.com 站点之外,我可以得到所有东西。

有什么方法可以设置吗?

【问题讨论】:

标签: apache .htaccess redirect https


【解决方案1】:

首先将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]

注意:清除浏览器缓存并进行测试。

【讨论】:

  • 我很感激!
【解决方案2】:

我终于能够完成这项工作:

<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>

【讨论】:

    猜你喜欢
    • 2019-11-15
    • 2017-05-03
    • 2018-10-19
    • 2019-08-12
    • 2019-02-04
    • 2017-06-17
    • 2017-08-25
    • 1970-01-01
    • 2016-06-18
    相关资源
    最近更新 更多