【发布时间】:2018-06-14 11:46:55
【问题描述】:
当我设置我的子域时,我错误地创建了一些链接。现在谷歌认为我的子域和根域都有一些页面。我需要解决这个问题,但我无法重定向整个子域。
我想做的例子:
https://sub.example.com/ (no redirect)
https://sub.example.com/keep-1 (no redirect)
https://sub.example.com/keep-2 (no redirect)
https://sub.example.com/move-1/* => https://example.com/move-1/*
https://sub.example.com/move-2/* => https://example.com/move-2/*
我已经尝试了许多 .htaccess 解决方案并且我很接近,但我无法弄清楚。这是我尝试过的:
尝试 #1 - 正确重定向,但不能作为解决方案,因为它会重定向子域中的所有内容
RewriteCond %{HTTP_HOST} ^sub\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NE]
尝试 #2 - 不重定向任何内容 - 似乎是正确的解决方案,但我认为我缺少有关重定向工作原理的一些内容...
RewriteCond %{HTTP_HOST} ^sub\.example\.com/move-1/ [NC]
RewriteRule ^(.*)$ https://example.com/move-1/$1 [L,R=301,NE]
尝试 #3 - 不重定向任何内容
RewriteCond %{HTTP_HOST} ^sub\.example\.com/move-1/(.*)$ [NC]
RewriteRule https://example.com/move-1/$1 [L,R=301,NE]
尝试 #4 - 不重定向任何内容
RewriteBase /
RewriteRule ^sub\.example\.com/move-1/(.*)$ https://example.com/move-1/$1 [R=301]
我的 .htaccess 文件位于根域的根 html 文件夹中,并且似乎具有控制权。我也从子域的根文件夹中尝试过这些,但没有重定向任何东西。
【问题讨论】:
标签: .htaccess redirect mod-rewrite subdomain