我的.htaccess
文件中包含此代码:
Options +SymLinksIfOwnerMatch
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([a-z]+)/([a-z]+)?$ index.php?lang=$1&loc=$2 [NC,L]
RewriteRule ^([a-z]+)/([a-z]+)/restaurants/?$ all_rest.php?lang=$1&loc=$2 [NC,L]
正如您所看到的,变量lang
和loc
可以是([a-z]+)
范围内的任何内容,但我不需要总范围我只需要单词:en
或chin
为lang
变量,hk
或kw
为loc
变量。
我试过这个:
RewriteRule ^([en][chin])/([hk][kw])/restaurants/?$ all_rest.php?lang=$1&loc=$2 [NC,L]
但我不知道为什么只适用于hk kw
y无效en chin
。
有什么想法吗?
答案 0 :(得分:1)
您正在使用与个别字符匹配的字符集。因此,[hk][kw]
会匹配这些:hk, hw, kk, kw
。你想要这个:
RewriteRule ^(en|chin)/(hk|kw)/?$ index.php?lang=$1&loc=$2 [NC,L]
RewriteRule ^(en|chin)/(hk|kw)/restaurants/?$ all_rest.php?lang=$1&loc=$2 [NC,L]