2

我需要将查询字符串中的“_”替换为“+”而不是重定向:

site.com/abc_def/

site.com/search.php?q=abc+def

我试过这个

RewriteRule ^([^/]+)/((.*)\_(.*))?$ /search.php?q=$1+$2 [R=301,L]
4

1 回答 1

2

这些是对您有用的两条规则:

RewriteEngine On

# first replace _ by + recursively
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^_]*)_(.*)$ /$1+$2 [L]

# once all _s are gone, rewrite to /search.php?q=<search>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^_]+)$ /search.php?q=$1 [L,QSA]
于 2013-10-13T02:43:58.487 回答