htaccess rewriterule转发特定文件夹

时间:2011-09-23 15:10:29

标签: .htaccess mod-rewrite

我需要一个.htaccess正则表达式的帮助。我想将此网址:www.aloha.com/foo/bar/sample.html转发给www/aloha/foo/bar/index.php?go=sample

我尝试使用

  

RewriteRule /foo/bar/^(.*)?.html /foo/bar/index.php?go=$1 [L]

但它不起作用。

我还有另一条与此规则冲突的重写规则。这就是我需要为这个特定文件夹创建另一个规则的原因。

  

RewriteRule ^(。*)?。html index.php?input = $ 1 [L]

1 个答案:

答案 0 :(得分:1)

RewriteRule ^foo/bar/(.*?)\.html$ /foo/bar/index.php?go=$1 [L]

你的一些语法不合适。例如,^表示字符类的开头或否定。另外,我假设你想要一个文件名,所以不要使用可选的捕获?

最后,我把捕获变得非贪婪。我鼓励你更进一步,更具体地说明你的捕获。

例如:

RewriteRule ^foo/bar/([^/]+)\.html$ /foo/bar/index.php?go=$1 [L]