代码之家  ›  专栏  ›  技术社区  ›  olpa

apache,允许文件名带有“?”

  •  5
  • olpa  · 技术社区  · 15 年前

    我想制作一个网站的静态副本,保留现有URL。问题是URL看起来像:

    http://mysite/index.php?id=XXX

    而Apache不想找到“index.php”文件?id=XXX”。相反,它将请求解释为查询“id=XXX”的文件“index.php”。

    如何让Apache停止处理问号?


    最后,我的解决方案是:

    1) 将文件重命名为“index.php”?id=XXX”到“index.php\u id=XXX”

    2) 添加到.htaccess:

    RewriteEngine On
    RewriteCond %{ENV:REDIRECT_STATUS} =""
    RewriteCond %{QUERY_STRING} !=""
    RewriteRule ^(.*)$ $1_%{QUERY_STRING} [L]
    
    1 回复  |  直到 15 年前
        1
  •  5
  •   Josh Lee ZZ Coder    15 年前

    Escape 这个 ? 作为 %3f : http://www.example.com/index.php%3fid=XXX .

    如果在具有索引的目录中列出该文件,Apache将正确生成这种格式的链接。但是,必须重写现有页面中的链接。

    推荐文章