.htaccess 在多域设置中将旧URL重定向到新URL

.htaccess 在多域设置中将旧URL重定向到新URL,.htaccess,redirect,.htaccess,Redirect,如何在多域设置中使用htaccess将旧URL重定向到新URL 我知道我可以写像这样的东西 Redirect 301 /old.html http://example.com/new.html 但是如果我有多个域使用相同的htaccess,并且可能有一些相同的命名站点,该怎么办呢。例如 http://example.com/old.html -> http://example.com/new.html http://othersite.com/old.html -> http://

如何在多域设置中使用htaccess将旧URL重定向到新URL

我知道我可以写像这样的东西

Redirect 301 /old.html http://example.com/new.html
但是如果我有多个域使用相同的htaccess,并且可能有一些相同的命名站点,该怎么办呢。例如

http://example.com/old.html -> http://example.com/new.html
http://othersite.com/old.html -> http://othersite.com/new.html

对于多个域,您需要使用mod rewrite:

RewriteEngine on


RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$
RewriteRule ^page\.html$ http://domain.com/newpage.html [L,R,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?domain2.com$
RewriteRule ^page\.html$ http://domain.com/newpage.html [L,R,NC]