且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何转换加号(+)号到" = +"与htaccess的?

更新时间:2022-11-27 18:11:12

我只是要去给你的具体例子的字面上的答案。不知道是否会真正帮助你:

 的RewriteCond%{QUERY_STRING} ^([+])$
 重写规则/index3.php$ index3.php?=(1%)[R,L]
 

您不能repleace每个 + 的QS,因为你需要一个单独的条件,首先与之相匹配的。


另外你原来的规则:

 重写规则^([^ / \。] +)+([^ / \。] +)?$ $ 1 = + $ 2 [R]
 

逃离了charclass将点是多余的, [^ /] 就足够了。你至少需要两组 / 之间的分隔符是有道理的。但是你不能在QUERY_STRING匹配存在,这是独立于当前的文件路径来处理。

请参阅阿尔索斯:ServerFault:所有你想知道的关于mod_rewrite规则,但不敢问 - 和 - HttpdWiki:操纵查询字符串

I want to convert every url which contains "+" to "=+"

for example that url:

http://www.bedavaemlaksitesi.com/mersinemlakrehberi210/index3.php?+  

should be like this:

http://www.bedavaemlaksitesi.com/mersinemlakrehberi210/index3.php?=+

tried that and few other lines but doesn't work so far, i'm guessing it causes a loop or something.

RewriteRule ^([^/\.]+)+([^/\.]+)?$ $1=+$2 [R]

I'm just gonna give you a literal answer for that specific example. Not sure if that will actually help you:

 RewriteCond  %{QUERY_STRING}  ^([+])$
 RewriteRule  /index3.php$  index3.php?=(%1)  [R,L]

You cannot repleace each + in the QS, as you do need a separate condition to match it first.


Also about your original rule:

RewriteRule ^([^/\.]+)+([^/\.]+)?$ $1=+$2 [R]

Escaping the dot in the charclass is redundant, [^/.] suffices. And you need at least a separator between the two groups / to make sense. But you can't match the query_string there, that's handled separately from the current filepath.

See alsos: ServerFault: Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask? -and- HttpdWiki: Manipulating the Query String