2

我建立了一个在开发中运行良好但在生产中无法正常运行的网站。我不知道问题是否与 .htaccess 或配置不正确的虚拟主机有关。本质上,问题在于我的自定义框架中的 URL 重写,它依赖于称为controlleraction的 URL 参数。访问诸如domain.com/account/new这样的 url将重写为domain.com/index.php?controller=account&action=new。相反,在$_SERVER我的引导程序开始时(在任何应用程序逻辑有机会弄乱任何东西之前)进行全局转储时,我收到了这个:

["QUERY_STRING"]=> string(41) "controller=index.php&action=index¶ms=" 

那个pilcrow(段落标记)来自哪里?不管我尝试什么 URL,它仍然会以这种方式出现。

注意:同一服务器上的其他站点可以毫无问题地进行 URL 重写。好像只有这一个。

我已验证 mod_rewrite 模块已加载并显示在php -i /phpinfo()中。

这是我的.htaccess:

RewriteEngine On
RewriteBase /

RewriteRule ^([^/]+/)*favicon\.ico$ assets/img/favicon.ico [L,NC]

RewriteCond %{REQUEST_URI} ^/assets.*$
RewriteRule ^(.*)$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !favicon\.ico
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]+)(/)([^/]+)(/)(.*) index.php?controller=$1&action=$3&params=$5 [L]
RewriteRule ^([^/]+)(/)(.*) index.php?controller=$1&action=$3&params= [L]
RewriteRule ^([^/]+)(/) index.php?controller=$1&action=index&params= [L]
RewriteRule ^([^/]+) index.php?controller=$1&action=index&params= [L]

开发环境:

MacOS 10.7
Apache 2.2.22
PHP 5.4.15

生产环境:

Linux (Kernel 2.6.32)
Apache 2.2.3
PHP 5.3.3

TL;博士; 我的 .htaccess 规则重写不正确,包括一个 pilcrow(段落标记),后跟“ms=”。这是我的 htaccess 规则的问题吗?这看起来像服务器问题吗?我正在撕扯我的头发试图弄清楚这一点。


编辑#1

我刚刚注意到,在我的 htaccess 中,类似这样index.php?controller=$1&action=$3&params=的内容包含“¶”,它是 pilcrow 符号的 HTML 实体,这完全可以理解为什么它变成该符号后跟ms=。现在更大的问题是为什么 htaccess 会处理 HTML 实体?

编辑#2

好吧,所以我一定是无知的。它之所以显示是因为我在浏览器中查看它。当我去“查看源代码”时,它通过["QUERY_STRING"]=> string(41) "controller=index.php&action=index&params=". 好吧,很公平,现在要弄清楚为什么它在 $1 变量中捕获文件名index.php 。唔。

4

1 回答 1

0

我无法解决我的问题,所以我重写了所有内容以在我的 .htaccess 中将所有值作为“资源”传递,例如:

RewriteRule ^(.*) index.php?resource=$1

然后在应用程序逻辑中我处理了所有的处理。感谢观看。

于 2013-06-10T17:53:03.710 回答