1

我正在使用 Codeigniter,我希望省略 url 的 index.php 部分。我设法在我的 webroot 上使用这样的 .htaccess 来做到这一点:

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

并使用

$config['index_page'] = '';

这行得通,像 subdomain.example.com/class/method 这样的网址按预期工作。

现在,我开始将视图的样式表和图像添加到我的 webroot 下名为“style”的文件夹中。但是,当我尝试访问这些时,我收到错误 404。我尝试以多种方式在我的视图中使用它们:

<img src="/style/img.jpg">
<img src="style/img.jpg">
<img src="<?php echo base_url('/style/img.jpg');?>">
<img src="http://subdomain.example.com/style/img.jpg"> 
<img src="<?php echo base_url();?>style/img.jpg">

base_url() 给出http://subdomain.example.com/。样式文件的用户模式设置为 755,如果这是有用的信息。我的猜测是,.htaccess 以某种方式阻止了这些。我用谷歌搜索了它,似乎很多人都遇到了类似的问题,但我没有找到一个可以帮助我使用图像并省略 index.php 的答案。这是我在搜索这些答案后使用 htaccess 得到的地方,但图像仍然没有运气:

#Enable mod rewrite
RewriteEngine On

#Removes access to CodeIgniter system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|style|images|robots\.txt|css)

RewriteRule ^(.*)$ index.php?/$1 [L]

我没主意了。

4

2 回答 2

1

尝试将.htaccess删除 index.php 的文件更改为此

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|ref_doc|media|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

这应该工作

于 2013-10-28T15:12:21.733 回答
0

尝试将这样的内容添加到您的重写规则中(在您的 htaccess 末尾):

 RewriteRule directoryname - [L]

抱歉,目前无法自己测试。

于 2013-10-28T15:08:54.003 回答