【问题标题】:Wildcard redirect for subdomains and URI子域和 URI 的通配符重定向
【发布时间】:2012-10-29 06:52:31
【问题描述】:

我在 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>

问候

【问题讨论】:

    标签: apache mod-rewrite apache2 apache2.2


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-09-27
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 2017-04-03
      • 2018-10-22
      • 1970-01-01
      相关资源
      最近更新 更多