与查询字符串htaccess的问题 [英] htaccess issue with query strings
问题描述
有一个现有的网站与平面文件结构吨的URL与查询字符串嘉豪的。我的问题是我写了一个CMS和已经安装使用查询字符串像一个自定义错误code页:
There was an existing site with a flat file structure with tons of urls with query strings galore. My issue is I wrote a CMS and have setup a custom error code page that uses a query string like:
ErrorDocument的404 /error.php?error$c$c=404
ErrorDocument 404 /error.php?errorcode=404
这样做的问题是,如果旧的URL损坏有这个将覆盖的ErrorDocument redirct查询字符串查询字符串。例如,如果你这样做
The issue with this is if the old broken url has a query string this overwrites the query string in the errordocument redirct. For example if you do
www.example.com/missingpage.php - 这将工作和重定向到404没有问题
www.example.com/missingpage.php - this will work and redirect to the 404 without issue.
但是,如果你
www.example.com/missingpage.php?anything=anything
www.example.com/missingpage.php?anything=anything
甚至
www.example.com/missingpage.php?
www.example.com/missingpage.php?
错误code = 404查询字符串不会使它的PHP页面,它抛出的一般消息我已经安装时错误code不匹配。问题是有很多很多的各种疯狂的查询字符串的链接,这样就很难单独过滤出来。
the errorcode=404 query string will not make it to the php page and it throws the generic message I have setup when the errorcode doesn't match. The problem is there are lots and lots of links with all kinds of crazy query strings so it is very hard to filter them out individually.
有没有人遇到了这个问题之前?
Has anyone ran into this issue before?
推荐答案
别的东西,你可以做的是使用mod_rewrite并追加查询字符串。我已经看到了这一点做的其他设置之前,因为的ErrorDocument
目标被放回通过URL映射引擎(至少在阿帕奇2.4)。
Something else that you can do is to use mod_rewrite and append the query string. I've seen this done on other setups before because the ErrorDocument
target gets put back through the URL mapping engine (at least in apache 2.4).
例如:
ErrorDocument 404 /error-doc-404
ErrorDocument 405 /error-doc-405
ErrorDocument 500 /error-doc-500
然后你有这样的:
And then you have this:
RewriteEngine On
RewriteRule ^error-doc-([0-9]{3})$ /error.php?errorcode=$1 [L]
这样一来,在地址栏中的URL不会得到改变。
This way, the url on the address bar does not get changed.
这篇关于与查询字符串htaccess的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!