编码URL中的特殊字符使用htaccess的重写 [英] Encoding special characters in url rewriting using htaccess

查看:134
本文介绍了编码URL中的特殊字符使用htaccess的重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个重写规则如下,它工作:

I have a rewrite rule as following,it is working:

RewriteRule area/(.*) listing.php?area=$1

但是,当我想用​​ 29%在里面,但是当我把它改写如下,我得到404错误:

But when I want to use %29 in it,but when I rewrite it as following, I get 404 error:

RewriteRule area/something%29/(.*)/ listing.php?area=$1 

逃逸 29% \%29 也不能工作。

推荐答案

阿帕奇%-de codeS尝试应用重写规则之前的URL路径。所以,你不应该使用%编码在你的重写规则。只需使用普通字符。

Apache %-decodes the url-path before trying to apply the rewrite rules. So you should not use %-encoding in your RewriteRule. Just use the normal character.

所以,你的情况,你应该只使用了不过是普通的前pression特殊字符,所以你应该在前面加上一个反斜杠那些在正则表达式的方式。因此,这将成为 \)

So in your case you should just use the ). ) however is a special character in regular expression, so you should escape those in the RegEx way by adding a slash in front. So it will become \).

上面你的规则应该成为:

Your rule above should become:

RewriteRule area/something\)/(.*)/ listing.php?area=$1 

这篇关于编码URL中的特殊字符使用htaccess的重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆