阿帕奇:mod_rewrite的:Spcaes&放大器;特殊字符的URL不工作 [英] Apache: mod_rewrite: Spcaes & Special Characters in URL not working

查看:159
本文介绍了阿帕奇:mod_rewrite的:Spcaes&放大器;特殊字符的URL不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用APACHE:mod_rewrite的定义一组规则rewritting网址

i am using APACHE:mod_rewrite to define a set of rules for rewritting URLS

我想这link                                                           to被显示为

i want this link                                                           to be displayed as

/myDIR/walls.php?f=All&of=0&s=Newest - > All.html

所以我用下面的规则

从文本(的.htaccess)

RewriteEngine  on
RewriteBase    /myDIR/   
RewriteRule ^All\.html$  papers.php?f=All&of=0&s=Newest

现在这些正在为传递变量
F =全部 = 0 S =最新这些都是在查询中使用,很明显,这些变量之一,即˚F有时有空格和特殊字符值,我无法避免,因为数据库已经在-place和所有我做的URL重写......

now these variables that are being passed as f=All of=0 s=Newest these are being used in query, OBVIOUSLY, and one of these variables, i.e f sometimes has values with spaces and special characters, and i can't avoid that because the database is already in-place and all i am doing rewrite of URLs....

现在,当我尝试这样定义的规则

NOW when i try to define a rule like this

我想这link                                                                                          to被显示为

i want this link                                                                                          to be displayed as

/myDIR/walls.php?f=Characters&安培;超级计算机和放大器;中= 0&安培; S =最新 - > 字符和放大器; Supers.html

这是不对的,我知道,因为不应该有任何空格..所以要作出正确的我这样定义规则

which is wrong i know because there shouldn't be any spaces.. so to make it right i define the rule like this

RewriteRule ^Characters%20%26%20Supers\.html$  papers.php?f=Characters%20%26%20Supers&of=0&s=Newest

它让我定义规则,但是当我点击我的链接我得到这个
404未找​​到错误的请求的URL / wallz /字符和放大器; Supers.html在此服务器上找到了

问:做什么

我的猜测就是我不应该做的事情里面的.htaccess HTML URL编码

my guess is i am not supposed to be doing HTML URL Encoding inside .htaccess

推荐答案

您的猜测是正确的。通过一个URL已经达到了mod_rewrite进行处理的时候,阿帕奇早已德codeD的URL为您服务。因此,如果你想检查任何其它-CN codeD字符,你需要用自己的文字重新presentations。

Your guess is correct. By the time that a URL has reached mod_rewrite for processing, Apache has already decoded the URL for you. Therefore, if you want to check for any otherwise-encoded characters, you need to use their literal representations.

由于空格在这里被用作分隔符,你还需要你的逃生空间:

Since whitespace is used as a delimiter here, you'd also need to escape your spaces:

RewriteRule ^Characters\ &\ Supers\.html$ papers.php?f=%0&of=0&s=Newest

我相信使用引号也将正常工作,所以下面应该是等价的(虽然它是未经测试):

I believe that using quotation marks will also work, so the following should be equivalent (though it's untested):

RewriteRule "^Characters & Supers\.html$" papers.php?f=%0&of=0&s=Newest

有关Apache的解码过程最后需要说明的是,它会自动删除多个斜线你。虽然你的榜样不相关的,它的网址是怎么之前将您的mod_rewrite规则转换的另一个例子。

A final note about Apache's decoding process is that it will automatically remove multiple slashes for you. While not relevant for your example, it's another example of how the URL is transformed prior to reaching your mod_rewrite rules.

这篇关于阿帕奇:mod_rewrite的:Spcaes&放大器;特殊字符的URL不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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