modrewrite问题

时间:2011-08-31 15:01:11

标签: php mod-rewrite

我使用以下规则遇到modrewrite问题。 我收到404错误,因为规则似乎不起作用。 有人可以提供如何让它运作的解决方案吗?

RewriteRule ^/catalogue/([^/\.]+)/results.html$ /search.php?data=$1 [L]

它应该像下面这样处理网址但是给我一个404:

http://www.mydomain.com/catalogue/europe/germany/results.html

提前感谢。

3 个答案:

答案 0 :(得分:1)

RewriteRule ^catalogue/(.+?)/results.html$ /search.php?data=$1 [L]

答案 1 :(得分:1)

您的示例网址不受重写规则的影响;使用[^/\.]+,您允许除正斜杠和点之外的所有字符,因此europe/germany不匹配,因为它有正斜杠。

我不知道你想要准确允许什么,但对于你的示例网址,你可以使用类似的东西:

RewriteRule ^/catalogue/([a-zA-Z/]+)/results.html$ /search.php?data=$1 [L]

允许az(大写和小写)以及正斜杠。

答案 2 :(得分:1)

尝试此规则:

RewriteRule ^/catalogue/(.+?)/results.html$ /search.php?data=$1 [l]

由于您的捕获模式,您的规则无效:

[^/\.]+

基本上意味着:

Match anything that is not a / or a . for as many times as possible.

但它会在url的第一个next /停止,这会导致它不匹配

相关问题