1

我正在使用 CodeIgniter,我正在尝试从 url 中删除 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>
4

1 回答 1

0

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

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
于 2013-08-21T15:29:42.237 回答