【发布时间】:2012-07-13 20:37:17
【问题描述】:
这些天我正在尝试使用 CodeIgniter。
默认情况下,它在 URI 中有 index.php,如下所示
http://www.example.com/index.php/home
home 是控制器内部的一个函数
但我不想要 index.php,所以我创建了 .htaccess 文件:
Allow from all
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|img|robots\.txt|script|css)
RewriteRule ^(.*)$ index.php/$1 [L]
基本上它会自动添加“index.php”,除非条件匹配。
但是事情是这样的:
对于这样的 URI:http://www.example.com/home
一切正常。
对于这样的 URI:http://www.example.com/home/
然后我网页中的相关链接变得疯狂。
例如:
css/common.css 被重定向到 index.php/home/css/common.css 导致找不到 css 文件。
日志是这样的:
strip per-dir prefix: [dir to my site]/home/css/common.css -> home/css/common.css
applying pattern '^(.*)$' to uri 'home/css/common.css'
rewrite 'home/css/common.css' -> 'index.php/home/css/common.css'
add per-dir prefix: index.php/home/css/common.css -> [dir to my site]/index.php/home/css/common.css
trying to replace prefix [dir to my site]/ with /
internal redirect with /index.php/home/css/common.css [INTERNAL REDIRECT]
add path info postfix: [dir to my site]/index.php -> [dir to my site]/index.php/home/css/common.css
strip per-dir prefix: [dir to my site]/index.php/home/css/common.css -> index.php/home/css/common.css
applying pattern '^(.*)$' to uri 'index.php/home/css/common.css'
pass through [dir to my site]/index.php
我该如何解决这个问题?
【问题讨论】:
标签: html apache .htaccess codeigniter