Codeigniter mod_rewrite和父文件夹

时间:2013-08-21 14:27:16

标签: codeigniter mod-rewrite codeigniter-url

我正在使用CodeIgniter,我正在尝试从网址中删除index.php。我在Apache中启用了mod_rewrite,我将索引设置为CI配置文件中的空白字符串,我使用的是页面底部的.htaccess文件。我认为部分问题可能是我的应用程序和系统文件夹不在我的文档根目录中。我的本地服务器文件夹结构如下所示:

mysite.dev/
-public_html (server root)
-application
-system
-.htaccess

我是这样做的,因为我读到了在public_html文件夹之外有应用程序和系统的额外安全性。但重写规则不起作用,我怀疑它与此有关。我对此比较陌生,所以我真的很感激任何帮助!

我的htaccess文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /#Removes access to the 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]

#When your application folder isn’t in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename ’application’ to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don’t have mod_rewrite installed, all 404′s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

1 个答案:

答案 0 :(得分:0)

我在.htaccess文件中使用了该代码,因为它对我有用。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]