升级后CodeIgniter 2.1.1 .htaccess问题

时间:2012-08-15 03:56:10

标签: .htaccess codeigniter url-rewriting codeigniter-2

我有一个客户网站使用CodeIgniter 1.7大约6年了,没有任何问题。但是,最近我将CodeIgniter框架更新为2.1.1,现在.htaccess存在问题。我已经在日志中确认它没有到达我的控制器所以我认为这纯粹是一个.htaccess问题。

我有几种典型的网址格式:

mysite.com/<page name here>, i.e. mysite.com/faq  
mysite.com/admin/<action here>, i.e. mysite.com/admin/login

目前我的.htaccess

RewriteEngine On

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/page/id/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(admin/*)$ index.php/$1 [L]

现在,显而易见的是,mysite.com/faq应该重写为mysite.com/page/id/faq,但它会抛出404。

转到mysite.com成功加载默认控制器,在本例中为主页或等效于mysite.com/home。所有管理员网址都完美无缺。 mysite.com/page/id/<page name here>也正常运作。

为了进行比较,在我升级CodeIgniter之前已经工作了6年的原始.htaccess是:

RewriteRule ^((images|styles|scripts|documents)/*.*)$ $1 [L]
RewriteRule ^(admin/*)$ index.php/$1 [L]
RewriteRule ^([a-zA-Z0-9]+)$ page/id/$1
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]

这个原始的行为与我目前正在尝试使用的行为完全相同。原件的重写日志如下:

[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'faq'
[rid#1db5120/initial] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/faq' pattern='^system.*' => not-matched
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'faq'
[rid#1db5120/initial] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/faq' pattern='^application.*' => not-matched
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^((images|styles|scripts|documents)/*.*)$' to uri 'faq'
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(admin/*)$' to uri 'faq'
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^([a-zA-Z0-9]+)$' to uri 'faq'
[rid#1db5120/initial] (2) [perdir C:/wamp/www/jb2/] rewrite 'faq' -> 'page/id/faq'
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] add per-dir prefix: page/id/faq -> C:/wamp/www/jb2/page/id/faq
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/page/id/faq -> page/id/faq
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'page/id/faq'
[rid#1db5120/initial] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='page/id/faq' pattern='!^(index\.php|robots\.txt|favicon\.ico)' => matched
[rid#1db5120/initial] (2) [perdir C:/wamp/www/jb2/] rewrite 'page/id/faq' -> 'index.php/page/id/faq'
[rid#1db5120/initial] (3) [perdir C:/wamp/www/jb2/] add per-dir prefix: index.php/page/id/faq -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#1db5120/initial] (2) [perdir C:/wamp/www/jb2/] strip document_root prefix: C:/wamp/www/jb2/index.php/page/id/faq -> /jb2/index.php/page/id/faq
[rid#1db5120/initial] (1) [perdir C:/wamp/www/jb2/] internal redirect with /jb2/index.php/page/id/faq [INTERNAL REDIRECT]
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'index.php/page/id/faq'
[rid#4f657d8/initial/redir#1] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/index.php/page/id/faq' pattern='^system.*' => not-matched
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'index.php/page/id/faq'
[rid#4f657d8/initial/redir#1] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/index.php/page/id/faq' pattern='^application.*' => not-matched
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^((images|styles|scripts|documents)/*.*)$' to uri 'index.php/page/id/faq'
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(admin/*)$' to uri 'index.php/page/id/faq'
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^([a-zA-Z0-9]+)$' to uri 'index.php/page/id/faq'
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#4f657d8/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'index.php/page/id/faq'
[rid#4f657d8/initial/redir#1] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='index.php/page/id/faq' pattern='!^(index\.php|robots\.txt|favicon\.ico)' => not-matched
[rid#4f657d8/initial/redir#1] (1) [perdir C:/wamp/www/jb2/] pass through C:/wamp/www/jb2/index.php

我一直在尝试的当前.htaccess的重写日志是:

[rid#4fb2e70/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#4fb2e70/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'faq'
[rid#4fb2e70/initial] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/faq' pattern='^system.*' => not-matched
[rid#4fb2e70/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#4fb2e70/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'faq'
[rid#4fb2e70/initial] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/faq' pattern='^application.*' => not-matched
[rid#4fb2e70/initial] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/faq -> faq
[rid#4fb2e70/initial] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'faq'
[rid#4fb2e70/initial] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='C:/wamp/www/jb2/faq' pattern='!-f' => matched
[rid#4fb2e70/initial] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='C:/wamp/www/jb2/faq' pattern='!-d' => matched
[rid#4fb2e70/initial] (2) [perdir C:/wamp/www/jb2/] rewrite 'faq' -> 'index.php/page/id/faq'
[rid#4fb2e70/initial] (3) [perdir C:/wamp/www/jb2/] add per-dir prefix: index.php/page/id/faq -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#4fb2e70/initial] (2) [perdir C:/wamp/www/jb2/] strip document_root prefix: C:/wamp/www/jb2/index.php/page/id/faq -> /jb2/index.php/page/id/faq
[rid#4fb2e70/initial] (1) [perdir C:/wamp/www/jb2/] internal redirect with /jb2/index.php/page/id/faq [INTERNAL REDIRECT]
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'index.php/page/id/faq'
[rid#1da50a0/initial/redir#1] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/index.php/page/id/faq' pattern='^system.*' => not-matched
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'index.php/page/id/faq'
[rid#1da50a0/initial/redir#1] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='/jb2/index.php/page/id/faq' pattern='^application.*' => not-matched
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(.*)$' to uri 'index.php/page/id/faq'
[rid#1da50a0/initial/redir#1] (4) [perdir C:/wamp/www/jb2/] RewriteCond: input='C:/wamp/www/jb2/index.php' pattern='!-f' => not-matched
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] add path info postfix: C:/wamp/www/jb2/index.php -> C:/wamp/www/jb2/index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] strip per-dir prefix: C:/wamp/www/jb2/index.php/page/id/faq -> index.php/page/id/faq
[rid#1da50a0/initial/redir#1] (3) [perdir C:/wamp/www/jb2/] applying pattern '^(admin/*)$' to uri 'index.php/page/id/faq'
[rid#1da50a0/initial/redir#1] (1) [perdir C:/wamp/www/jb2/] pass through C:/wamp/www/jb2/index.php

实际的升级过程只是在CodeIgniter框架上,并将文件重新组织到单独的applicationsystem文件夹中,除了所需的最小更改之外,没有触及我的实际自定义代码。升级过程的一部分。

我已经尝试了大约十亿种不同的.htaccess命令组合试图使这个东西工作,并且无法让“正常”页面和管理页面正确加载相同的配置。最后我的问题是为什么升级CodeIgniter会神奇地破坏URL重写,但我很乐意再次使用它。

有人有建议吗?我会喜欢另一双眼睛。

2 个答案:

答案 0 :(得分:1)

所以我终于得到了另一个论坛的建议。我将$config[‘uri_protocol’]AUTO更改为PATH_INFO并且神奇地工作了。我确实必须添加一行来处理admin/*网址格式,所以我的最终.htaccess就是这样:

RewriteRule ^(admin/*)$ index.php/$1 [L]
RewriteRule ^([a-zA-Z0-9]+)$ page/id/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  

答案 1 :(得分:0)

您的.htaccess文件是否在正确的文件夹中? CodeIgniter使用几个.htaccess文件,我相信系统和应用程序中的一个文件说Deny From All和上面的那个有你的规则。