写一个RewriteRule

时间:2014-08-21 16:22:33

标签: apache .htaccess mod-rewrite redirect

我有一个网站,最近有一个域名更改,我试图设置规则,以包括重定向规则集之后的任何东西(子域目前工作,但文件exensions不工作)当前规则集我到位的是:

RewriteRule ^subdomain/(.*)$ http://subdomain.example.com [R=301,L]

如果我访问www.example.com/subdomain/或www.example.com/subdomain/another_directory/,它会重定向到相应的网站,但如果我访问www.example.com/subdomain/file.ext或www.example.com/subdomain/another_directory/file.ext,重定向不起作用。我知道我需要更改正则表达式以使其正常工作,但我不确定它需要更改为什么。

2 个答案:

答案 0 :(得分:0)

您没有在目标网址中使用捕获的群组。像这样使用它:

RewriteRule ^subdomain/(.*)$ http://subdomain.example.com/$1 [R=301,L,NE,NC]

答案 1 :(得分:0)

You don't need mod_rewrite for this.

更简单,更轻便的方法

RedirectMatch ^/subdomain/ http://subdomain.example.com/