.htaccess 如果url包含word,则htaccess重定向到不同的域

.htaccess 如果url包含word,则htaccess重定向到不同的域,.htaccess,redirect,.htaccess,Redirect,我有一个网站,我分裂成两个。因此,我想根据url是否包含特定关键字,将所有页面重定向到其他两个域之一。在.htaccess中类似于以下内容: if ("keyword" is in the url) site A redirects to site B else site A redirects to site C 以下是我在你这样的案例中使用的一些规则,它很好用。希望这有帮助 RewriteCond %{HTTP_HOST} www\.oldhost\.com

我有一个网站,我分裂成两个。因此,我想根据url是否包含特定关键字,将所有页面重定向到其他两个域之一。在.htaccess中类似于以下内容:

if ("keyword" is in the url) site A redirects to site B
else site A redirects to site C

以下是我在你这样的案例中使用的一些规则,它很好用。希望这有帮助

RewriteCond   %{HTTP_HOST}               www\.oldhost\.com
RewriteCond   %{REQUEST_URI}             ^/yourkeyword/.*
RewriteRule   ^/yourkeyword/(.*)         http://www.newdomain.com/$1 [R,L]
这可以转化为以下规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule keyword http://www.siteA.com%{REQUEST_URI} [NE,L,R=301,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.siteB.com%{REQUEST_URI} [NE,L,R=301]

嗨,我的回答有用吗?如果你能提供更多的信息,也许我可以再帮你一把。
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule keyword http://www.siteA.com%{REQUEST_URI} [NE,L,R=301,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.siteB.com%{REQUEST_URI} [NE,L,R=301]