一个重写规则有效......另一个几乎相同的规则不行

时间:2017-05-04 02:24:41

标签: .htaccess url-rewriting

也许有人可以告诉我为什么.htaccess文件中的以下内容表现得很奇怪:

RewriteRule    ^brand/b([0-9]+)/?$    articles.php?id=b$1    [NC,L]
RewriteRule    ^brand/h([0-9]+)/?$    categories.php?id=h$2    [NC,L]

根据这些规则,这个

example.com/brand/b1234

重定向到

example.com/articles.php?id=b1234

但是这个

example.com/brand/h1234

不会重定向到

example.com/categories.php?id=h1234

应该如此。

我在.htacess中的代码中是否遗漏了任何会导致其中一个工作而不是另一个工作的代码?

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试这样,

# incoming request neither file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^brand/b([0-9]+)/?$ articles.php?id=b$1 [NC,L]
RewriteRule ^brand/h([0-9]+)/?$ categories.php?id=h$1 [NC,L]

你必须确实把1美元而不是2美元。

相关问题