在htaccess中的查询字符串中用连字符替换空格

时间:2014-09-23 12:40:09

标签: .htaccess

当我输入这样的网址时,我需要这样:http://www.example.com/Fountain%20Hills-condos-townhouses然后%20或空格被连字符替换。 我的htacces是:

#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule (.*)-condos-townhouses$ index.php?cond_option=and&page=1&nextprev=0&searchBtn=0&displaylim=30&search_by=$1&search_cat_type=city&keyword=City&propType=2&listing_types=2&sortby=&searchpost=1&popup_in_seconds=1&is_popup_show=1&last_neighborhood=20&last_school=50&last_zips=20

我应该得到$ _REQUEST ['search_by']的值是Fountain-Hills

1 个答案:

答案 0 :(得分:0)

尝试在RewriteEngine On下面添加此内容:

RewriteCond %{QUERY_STRING} ^(.+)(?:\ |%20)(.+)$
RewriteRule ^(.*)$ /$1?%1-%2 [L,R]