php - .htaccess 从子域重定向到子域

标签 php wordpress apache .htaccess redirect

一个新客户需要我的帮助,他们的网络开发人员搞砸了 - 在草稿/测试服务器上构建了网站,但忘记阻止 Google 等。我非常感谢这里社区的帮助,我不是 HTACCESS 重定向方面的专家。

正如我所说,另一个网站开发人员在他们的草稿服务器上设置了客户草稿网站,该网站已经存在了几个月,但是他们忘记向搜索引擎隐藏它,因此内容已被 Google 等索引 - 这将触发如果网络将新网站上线,则重复内容会受到惩罚,新网站实际上将毫无用处。

我可以访问草稿站点/服务器,并且可以修改 HTACCESS 文件,因此当新站点上线时,我希望有正确的重定向。该网站上有一些子域(这是一个多语言网站),因此有点棘手。

该网站是基于Wordpress构建的

测试服务器上的网站结构如下所示。所有文件页面名称和文件名都是相同的,只是移动到新服务器。

http://clientdomain.testserver.com
http://it.clientdomain.testserver.com
http://fr.clientdomain.testserver.com
http://es.clientdomain.testserver.com
http://de.clientdomain.testserver.com
http://ko.clientdomain.testserver.com
http://pt.clientdomain.testserver.com
http://ru.clientdomain.testserver.com
http://tr.clientdomain.testserver.com
http://cn.clientdomain.testserver.com

重定向需要转到此处:

http://clientdomain.com
http://it.clientdomain.com
http://fr.clientdomain.com
http://es.clientdomain.com
http://de.clientdomain.com
http://ko.clientdomain.com
http://pt.clientdomain.com
http://ru.clientdomain.com
http://tr.clientdomain.com
http://cn.clientdomain.com

测试服务器上现有的 HTACCESS 文件如下所示

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

我非常感谢对此的任何帮助。

有一些现有的线程包含 HTACCESS 难题的所有部分,但我有点困惑:

如何从 .htaccess 中的一个子域重定向到另一个子域? How can I redirect from one subdomain to another in .htaccess?

亲切的问候, GG

最佳答案

如果是我,我不会费心去搞重定向,把网址从索引中删除。 Google 将在 24 小时内删除它们,现在有时会更快。

将开发域添加到您的网站站长工具帐户并进行验证。然后转到 Google 索引 -> 删除网址;

enter image description here

只需在删除请求中输入值 / 即可告诉 Google 删除该域索引中的每个网址。

enter image description here

然后将阻止 robots.txt 文件添加到站点根目录;

User-agent: *
Disallow: /

我通常做的事情(尽管有 robots.txt 和基本的身份验证保护 - git 灾难/恶作剧,这种情况已经在我身上发生过几次)是提示 Google 立即重新索引该网站。转到“抓取”->“以 Google 方式获取”

enter image description here

将输入框留空,这样它就会获取整个网站,然后只需点击“获取”按钮即可。当 Google 获取它后,单击“提交到索引”按钮。

enter image description here

您会惊讶地发现,现在这一切发生得如此之快,如果幸运的话,过去需要几周的时间。

编辑

为了确保这种情况不会发生在其他发现此问题的人身上,阻止其将开发站点编入索引的最佳方法不是 robots.txt 文件或通过 .htaccess 文件使用基本身份验证(如前所述)提到很容易意外删除这些)。您应该通过 vhosts 文件在开发站点上启用基本身份验证。

关于php - .htaccess 从子域重定向到子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28344716/

相关文章:

php - 如何将文本字符串批量转换为具有 MySQL 关系的唯一 ID

href 中的 PHP Mailgun 错误链接

html - 溢出在横幅插件中隐藏/可见

php - 如何阻止 100,000 多个单独的 IP 地址

apache - 执行 hdfs zkfc 命令时出错

php - 如何在 Windows 中运行 PHPUnit 测试?

php - 在 Laravel 中添加时间至今查询

html - 缩小比例以响应时,如何将这些图像定位在 Logo 下方?

javascript - wp_localize_script 不适用于 jquery 句柄

apache - 基于不同主机的 AuthUserFile 的不同路径