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!

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

报告相同问题?

悬赏问题

  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接