Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当 url 以“word1”或“word2”结尾时,我厌倦了在第一个斜杠之前获取所有字符串,并且我使用以下代码:
RewriteRule ^(.+)/word1|word2/?$ index.php?query=$1 [NC]
我对两端有“word1”的url没有任何问题,但是如果url以“word2”结尾,Apache不会向“query”变量返回任何值
您需要对表达式中的交替进行分组:
^(.+)/(?:word1|word2)/?$
如果没有分组,您的表达式意味着:
^(.+)/word1 或者 word2/?$
^(.+)/word1
word2/?$
利用:
RewriteRule ^(.+)/(word1|word2)/?$