【问题标题】:Apache: RewriteRule removing trailing dotApache:RewriteRule 删除尾随点
【发布时间】:2011-01-03 14:55:31
【问题描述】:

这是我的 .htaccess 规则:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)/(.*)$ index.php?var1=$1&item=$2&var2=%{REQUEST_URI} [NC,L]
RewriteRule ^(.*)$ index.php?var1=$1 [NC]

这是一个网址(末尾有一个点): http://localhost/test/secondvar.

问题是尾随点不在var2 GET 变量内

我使用了print_r($_GET),这是上面网址的结果:

数组([var1] => test [var2] => secondvar [uri] => /test/secondvar.)

所以我的问题是,如何从 URL 中获取尾随点作为 var 的参数?如您所见,REQUEST_URI 表明 apache 知道该点。

我知道我不能将路径作为GET 参数发送并注意从 PHP 中读取 URI 中的路径,但我想知道为什么点没有出现以及如何修复它,如果有的话复杂的我宁愿选择直接的 PHP 解决方案。

编辑:不仅是尾随点而且是尾随?太……=[

【问题讨论】:

  • 您将无法轻松获得尾随?因为它不是 {REQUEST_URI} 的一部分,所以它被解释为您的请求 uri 和查询字符串之间的分隔符。我很快试图重现问题,但我做不到。尾随 .奇迹般有效。你用的是什么版本的php和apache?
  • PHP 版本 5.3.0,Apache 2.0 处理程序

标签: php apache mod-rewrite trailing


【解决方案1】:

可能只是 php 不包括尾随点。我知道他们经常将 POST/GET 中的点转换为下划线。我会做的

explode('/',$_SERVER['REQUEST_URI'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 2017-09-19
    • 2018-11-15
    • 2012-01-26
    • 2015-04-27
    • 2020-07-23
    相关资源
    最近更新 更多