重写规则替换符号

时间:2013-12-05 14:10:08

标签: php regex apache .htaccess mod-rewrite

我的网站是mywebsite.com/this.php?That=Blah+Blah

我的重写规则是

RewriteEngine on
RewriteRule ^That/([A-Za-z0-9-+]+)/?$ this.php?That=$1 [NC]

RewriteEngine on
RewriteRule ^([A-Za-z0-9-+]+)/?$That/$1 [NC]

当我输入mywebsite.com/Blah+Blah时它工作正常。

当我输入mywebsite.com/Blah-Blah以获得相同的结果时,如何使用 - 符号更改+符号?

1 个答案:

答案 0 :(得分:1)

您可以为hyphen to +转化添加新规则:

RewriteEngine on

RewriteRule ^([^-]*)-(.*)$ /$1\+$2 [L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w+]+)/?$ /this.php?That=$1 [L,QSA,NE]