如何在Apache Server中设置CodeIgniter .htaccess文件

use*_*324 0 php apache codeigniter

我在Windows 7操作系统上安装了Apache 2.2,Php 5.4.5和Mysql 5.5.27.我的localhost位置是G:/ local_server.我已下载CodeIgniter_2.1.3并解压缩到local_server并重命名CodeIgniter.我在CodeIgniter文件夹上创建.htaccess文件并通过以下代码:

<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On

# If your website begins from a folder e.g localhost/my_project then 
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase / CodeIgniter/

# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)

# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)

# No rewriting
RewriteRule ^(.*)$ - [PT,L]

# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

然后我从application/config/config.php更改了以下行

$config['index_page'] = 'index.php';  to $config['index_page'] = '';

$config['uri_protocol'] = 'AUTO'; to $config['uri_protocol'] = 'REQUEST_URI';
Run Code Online (Sandbox Code Playgroud)

我还从Apache httpd.conf中删除#行:

LoadModule rewrite_module modules/mod_rewrite.so
Run Code Online (Sandbox Code Playgroud)

但我仍然无法隐藏CodeIgniter中的index.php文件.:(

帮助赞赏.:)

Dev*_*ung 7

这是我很好的'可靠的Codeigniter .htaccess文件:

RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(templates|plugins)
  RewriteRule ^(.*)$ index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)

然后将您的基础重写为您需要的任何内容,添加您需要访问的目录(我有模板和插件),您应该好好去.

当然,还要确保Apache启用了mod_rewrite,否则你将无法获得任何结果!