是的,因为regex ^health-institute-([a-zA-Z\-]+)-([a-zA-Z\-]+)$
在第一个规则也匹配 health-institute-app-mycity
.
你需要扭转这两个指示,因此更具体的规则是第一次。
例如:
RewriteRule ^health-institute-app-([a-zA-Z-]+)$ search.php?city=$1 [L]
RewriteRule ^health-institute-([a-zA-Z-]+)-([a-zA-Z-]+)$ search.php?city=$1&speciality=$2 [L]
(没有必要反斜杠-逃的连字符当在开始或结束符类。)
然而,regex在(现在)的第二项规则可能是模糊的,因为连字符的(-
)是用于划定该两个值(city
和 speciality
),但连字也包括在两个性质的类别,这样它可以大概能一部分的价值观本身。 然而,既 city
和 speciality
不能既含有连字符的,尽管regex似乎允许这一点。
例如,如何应请求 health-institute-foo-bar-baz-qux
要解决? 由于quantifier +
是 贪婪的,这将目前的结果 search.php?city=foo-bar-baz&speciality=qux
. 如果有连字符的 speciality
(作为建议这种可能的情况下通过regex)它将永远不会是匹配的。
health-institute-foo-bar-baz-qux
解决? 可以的city
含有连字符的?