0

我在 Windows 7 操作系统上安装了 Apache 2.2、Php 5.4.5 和 Mysql 5.5.27。我的本地主机位置是 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>

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

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

$config['uri_protocol'] = 'AUTO'; to $config['uri_protocol'] = 'REQUEST_URI';

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

LoadModule rewrite_module modules/mod_rewrite.so

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

帮助表示赞赏。:)

4

1 回答 1

8

这是我的好'ol可信赖的Codeigniter .htaccess文件:

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

然后将您的基础重写为您需要的任何内容,添加您需要访问的目录(我在那里有模板和插件),您应该一切顺利。

当然,还要确保 Apache 启用了 mod_rewrite,否则你将无处可去!

于 2013-03-12T21:54:34.473 回答