htaccess替换查询中的字符并重定向 [英] htaccess replace character in query and redirect
本文介绍了htaccess替换查询中的字符并重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在查询字符串中将'_'替换为'+',而不是重定向:
I need to replace '_' to '+' in query string than redirect:
site.com/abc_def /
到
site.com/search.php?q = abc + def
我尝试了此
RewriteRule ^([^/]+)/((.*)\_(.*))?$ /search.php?q=$1+$2 [R=301,L]
推荐答案
以下是两条适用于您的规则:
These are 2 rules that should work for you:
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]
这篇关于htaccess替换查询中的字符并重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文