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

如何在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!

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

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面