使用.htaccess从网址中删除加号

时间:2015-06-23 07:06:07

标签: php regex apache .htaccess mod-rewrite

我目前的网址是:

http://localhost/mywbsite/search/one+piece/149

我想将链接改为像这样

http://localhost/mywbsite/search/one-piece/149

我已经使用此代码的.htaccess文件

Options -MultiViews
RewriteEngine On
RewriteBase /indianrealitybytes/

RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC]
RewriteRule ^ search/%1/%2? [R=301,L]

RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC]

我不知道在哪里更改以删除加(+)符号到破折号( - )符号

1 个答案:

答案 0 :(得分:2)

您可以为+/-转化添加新规则:

Options -MultiViews
RewriteEngine On
RewriteBase /indianrealitybytes/

RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC]
RewriteRule ^ search/%1/%2? [R=301,L]

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

RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC]