3

我在 apache 中创建 pernament (301) 重定向时遇到问题:

我有 2 个域:
olddomain.com有许多子域
newdomain.com

我想做重定向,如:

如果用户输入http://anysubdomain.olddomain.com应该被重定向到http://anysubdomain.newdomain.com

如果用户输入http://olddomain.com/something应该被重定向到http://newdomain.com/something

如果用户输入http://olddomain.com/different/index.html应该被重定向到http://newdomain.com/different/index.html

如果用户输入http://example.olddomain.com/ex/index.html应该被重定向到http://example.newdomain.com/ex/index.html

我不知道我应该如何设置:

<VirtualHost *:80>
  ServerName olddomain.com
</VirtualHost>

问候

4

1 回答 1

1

要将您的所有请求从旧域重定向到新域,我将使用以下内容。

RewriteCond %{HTTP_HOST} ^(.*\.)?olddomain\.com [NC]
RewriteRule ^(.*)$ http://%1newdomain.com/$1 [R=301,L]

它匹配子域和请求 URI,并将它们与新域合并。如果没有子域,它将继续匹配请求并在没有子域的情况下重定向。

于 2012-11-09T04:57:35.283 回答