apache,允许文件名带有“?" [英] apache, allow filenames with '?'
问题描述
我想制作一个网站的静态副本,并保留现有的URL.问题在于网址看起来像这样:
I want to make a static copy of a site, retaining existing URLs. The problem is that the URLs looked like:
http://mysite/index.php?id = XXX
,Apache不想找到文件"index.php?id = XXX".而是将查询解释为带有查询"id = XXX"的文件"index.php".
and Apache does not want to find the file "index.php?id=XXX". Instead, it interprets the request as the file "index.php" with the query "id=XXX".
如何要求Apache停止处理问号?
How can I ask Apache to stop handling the question mark?
最后,我的解决方案:
1)将文件从"index.php?id = XXX"重命名为"index.php_id = XXX"
1) rename the files from "index.php?id=XXX" to "index.php_id=XXX"
2)添加到.htaccess:
2) Add to .htaccess:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteCond %{QUERY_STRING} !=""
RewriteRule ^(.*)$ $1_%{QUERY_STRING} [L]
推荐答案
转义 ?
作为%3f
:http://www.example.com/index.php%3fid=XXX
.
如果在具有索引的目录中列出文件,则Apache将正确生成此格式的链接.但是,您必须重写现有页面中的链接.
If you list the file in a directory that has indexes on, Apache will correctly generate links of this format. You must, however, rewrite the links in the existing pages.
这篇关于apache,允许文件名带有“?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!