dsk88199 2013-03-12 19:42
浏览 50
已采纳

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

I have installed Apache 2.2, Php 5.4.5 and Mysql 5.5.27 on Windows 7 Operating System. My localhost location is G:/local_server. I have downloaded CodeIgniter_2.1.3 and extract to local_server and rename CodeIgniter. I crate a .htaccess file on CodeIgniter folder and Past this following code:

<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>

Then I changed following line from application/config/config.php

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

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

I have also delete # from Apache httpd.conf following line:

LoadModule rewrite_module modules/mod_rewrite.so

But still I can’t hide index.php file from CodeIgniter. :(

Help appreciated. :)

  • 写回答

1条回答 默认 最新

  • doulan7166 2013-03-12 21:54
    关注

    Here's my good 'ol trusty Codeigniter .htaccess file:

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

    Then rewrite your base to whatever you need, add the directories you need to access (I have templates and plugins there) and you should be good to go.

    Of course, also make sure Apache has mod_rewrite enabled otherwise you won't get anywhere!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?