.htaccess用条件重写

时间:2014-10-04 22:41:30

标签: regex .htaccess

我陷入了重写。

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-_]+)/?$ index.php?p=$1 [NC,L]
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)?$ index.php?p=$1&key=$2

上面应该匹配

mydomain.com/page
mydomain.com/page/
mydomain.com/page/key
mydomain.com/page/key/

但是在某些情况下,我需要匹配/specific_page_here/url /将被重写为index.php?p=$1&url=$2

1 个答案:

答案 0 :(得分:0)

我认为有一个问题是你有一个' - '那是不被接受的。正则表达式应为[a-zA-Z0-9 -_]

如果您想匹配特定页面,只需执行以下确切文本:

RewriteRule ^my_page/([a-zA-Z0-9\?=&\/\.:\-_@;%]+)$ index.php?p=specific&url=$1 [NC,L]