3

我完全被 htaccess 重写无法在我的服务器上运行。这是 Codeigniter 的基本 index.php 重写,在我的 Mac 上开发时工作正常,但在我的服务器上失败(CentOS、Apache 2、WHM)

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

尝试加载 /about/ 将显示 index.php 页面。/index.php/about 将显示正确的页面。我已经尝试了所有我能想到的选项组合,但都无济于事。我的 rewrite.log 示例如下。

[dev.tirius.co.uk/sid#5d65288][rid#5e37c00/initial] (3) [per-dir /home/tirius/subdomains/dev/public_html/] add path info postfix: /home/tirius/subdomains/dev/public_html/about -> /home/tirius/subdomains/dev/public_html/about/
[dev.tirius.co.uk/sid#5d65288][rid#5e37c00/initial] (3) [per-dir /home/tirius/subdomains/dev/public_html/] strip per-dir prefix: /home/tirius/subdomains/dev/public_html/about/ -> about/
[dev.tirius.co.uk/sid#5d65288][rid#5e37c00/initial] (3) [per-dir /home/tirius/subdomains/dev/public_html/] applying pattern '^(.*)$' to uri 'about/'
[dev.tirius.co.uk/sid#5d65288][rid#5e37c00/initial] (2) [per-dir /home/tirius/subdomains/dev/public_html/] rewrite about/ -> /index.php/about/
[dev.tirius.co.uk/sid#5d65288][rid#5e37c00/initial] (1) [per-dir /home/tirius/subdomains/dev/public_html/] internal redirect with /index.php/about/ [INTERNAL REDIRECT]
[dev.tirius.co.uk/sid#5d65288][rid#5e3f7c8/initial/redir#1] (3) [per-dir /home/tirius/subdomains/dev/public_html/] add path info postfix: /home/tirius/subdomains/dev/public_html/index.php -> /home/tirius/subdomains/dev/public_html/index.php/about/
[dev.tirius.co.uk/sid#5d65288][rid#5e3f7c8/initial/redir#1] (3) [per-dir /home/tirius/subdomains/dev/public_html/] strip per-dir prefix: /home/tirius/subdomains/dev/public_html/index.php/about/ -> index.php/about/
[dev.tirius.co.uk/sid#5d65288][rid#5e3f7c8/initial/redir#1] (3) [per-dir /home/tirius/subdomains/dev/public_html/] applying pattern '^(.*)$' to uri 'index.php/about/'
[dev.tirius.co.uk/sid#5d65288][rid#5e3f7c8/initial/redir#1] (1) [per-dir /home/tirius/subdomains/dev/public_html/] pass through /home/tirius/subdomains/dev/public_html/index.php

如您所见,htaccess 已被拾取并且 mod_rewrite 已启用并正在工作,但似乎没有任何内容被附加到 index.php

这一定是一个 Apache 配置问题,但我真的不知道它可能是什么。

来自 httpd.conf 的示例

<Directory "/">
    Options ExecCGI FollowSymLinks IncludesNOEXEC Indexes MultiViews SymLinksIfOwnerMatch
    AllowOverride All
</Directory>
4

1 回答 1

1

这是我在 CentOS 上的 .htaccess:

RewriteCond $1 !^(index\.php|images|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php?/$1 [L]

注意正斜杠前的问号。

我认为这与将 PHP 作为 FastCGI 运行有关。我相信问号使前面的字符可选(即它也将匹配 index.ph)。我已经尝试对此进行更多研究,但找不到明确的原因。我想我只是尝试了我在寻找时可以找到的重写规则的所有变体,并没有费心问它为什么有效。

很高兴有帮助。

于 2012-07-27T08:46:22.710 回答