简体   繁体   English

htaccess-将所有流量重定向到除现有301之外的其他域

[英]htaccess - Redirecting all traffic to another domain except existing 301's

My htaccess file is filled with 301 redirects like such: 我的htaccess文件充满了301重定向,例如:

Redirect 301 /old-page.html https://www.example.com/new-page

There are about 100 of these redirects. 这些重定向大约有100个。 What I would like to do is redirect all traffic going to the old site to go to the new site excluding the existing 301's 我想做的是将除旧301站点外的所有流量重定向到旧站点,再转到新站点

So if someone goes to old-site.com/old-page.html it will take them to new-site.com/new-page and if someone goes to old-site.com/random-page.html it will take them to new-site.com - just the home page. 因此,如果有人访问old-site.com/old-page.html ,它将带他们进入new-site.com/new-page ;如果有人访问old-site.com/random-page.html ,它将带他们到new-site.com - new-site.com仅是主页。

Is it possible to do this using mod_rewrite and mod_alias without rewriting the current 301's? 是否可以使用mod_rewrite和mod_alias来执行此操作而无需重写当前的301?

You need to use a RewriteCond in front of all your rules like this: 您需要在所有规则之前使用RewriteCond ,如下所示:

RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]

If you want all the following rules to be processed as well DO NOT use the L (last) flag in the RewriteCond statement. 如果还希望处理以下所有规则,请不要在RewriteCond语句中使用L(最后一个)标志。

Source: Redirect all urls exactly, just change domain name 来源: 完全重定向所有网址,只需更改域名

You can keep all your 301 rules. 您可以保留所有301规则。 Just insert this generic 301 rule below your existing rule : 只需将此通用301规则插入您现有的规则下方

# all existing 301 rules go here

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?old-site\.com$ [NC]
RewriteRule ^ http://new-site.com/? [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM