RewriteRule保留域和更改子目录

时间:2016-04-19 13:27:52

标签: .htaccess redirect mod-rewrite

我有多个域指向同一个webserver目录。 我正在寻找一个RewriteRule,它在输入特定的URL时将用户重定向到子文件夹。但域名必须保持不变。

我需要什么:

    www.domain1.de/special
    should redirect the user to:
    www.domain1.de/redirect/special.php

    www.domain2.de/special
    should redirect the user to:
    www.domain2.de/redirect/special.php

通常我会像这样重定向:

Redirect /special http://www.domain1.de/redirects/special.php

但是这个解决方案不适用于2个不同的域,因为你总是会在domain1.de

我尝试了很多不同的解决方案。简单的例子:

RewriteRule http://www.domain1.de/special http://www.domain1.de/redirect/special.php
RewriteRule http://www.domain2.de/special http://www.domain2.de/redirect/special.php

RewriteCond %{HTTP_HOST} ^(.*)domain1.de [NC]
RewriteRule ^special/ http://domain1.de/redirects/special.php [R=301,L]

任何解决方案吗?

1 个答案:

答案 0 :(得分:0)

找到解决方案:

RewriteRule ^/?special(.*)$ /redirect/special.php$1 [R=302,L]