【问题标题】:apache rewrite module not transferring $_GET arrayapache 重写模块不传输 $_GET 数组
【发布时间】:2013-04-01 07:08:00
【问题描述】:

我在我的应用程序中使用了简单的 URL 重写。

RewriteEngine On

RewriteRule ^show/([a-zA-Z0-9]+)/([0-9]+)$ /show.php?d=$1&id=$2
RewriteRule ^sitemap/([a-zA-Z0-9]+)$ /sitemap.php?d=$1
RewriteRule ^sitemap/([a-zA-Z0-9]+)/([0-9]+)$ /sitemap.php?d=$1&page=$2

所有重定向都很好,但问题在于它们没有在过程中传输的 url 参数。

即,我到达了example.com/show/district/id,但脚本的行为就好像它到达了example.com/show.php。我在php中使用var_dump()进行调试,var_dump($_GET)返回了一个空数组。

注意:我是 htaccess 和 url 重写的新手,所以实际上无法从任何其他问题中找到我的答案,请帮助。

【问题讨论】:

  • example.com/district/id 将不符合您的任何规则。是不是笔误?
  • @Mike Anthony 这是一个错字,你能帮我解决这个问题吗?我已经编辑过了。

标签: apache .htaccess url mod-rewrite url-rewriting


【解决方案1】:

尝试使用以下修改后的代码:

Options -MultiViews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^show/([a-zA-Z0-9]+)/([0-9]+)$ show.php?d=$1&id=$2 [L,QSA]
RewriteRule ^sitemap/([a-zA-Z0-9]+)$ sitemap.php?d=$1 [L,QSA]
RewriteRule ^sitemap/([a-zA-Z0-9]+)/([0-9]+)$ sitemap.php?d=$1&page=$2 [L,QSA]

关于多视图的说明:

如果您不使用-MultiViews,服务器会自动假定您正在尝试直接运行show.php,因为它会查找show.*。它知道文件show不存在,因此会搜索以show开头的文件。

更多信息请参见this document

【讨论】:

  • 您使用的是自己的脚本还是框架?我想知道$_GET 数组是否已被故意清空,以便使用另一个函数对其进行访问。
  • 还有,您的网站还在吗?如果这是可能的,我想看看它。
  • 你听说过这样的问题吗,或者会不会是mod_rewrite模块配置的问题。所有规则都适用于我的本地服务器与 apache 2.2。
  • 我认为这与您的重写无关。我认为问题可能来自脚本。然而,我可能是错的。我可能遗漏了什么。
  • 你能把你的整个.htaccess贴出来吗,如果你上面的不是全部吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-07
  • 1970-01-01
  • 1970-01-01
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 2015-06-30
相关资源
最近更新 更多