【问题标题】:codeigniter htaccess not loaded?未加载codeigniter htaccess?
【发布时间】:2012-11-19 09:09:34
【问题描述】:

我创建的 htaccess 没有正常运行,为什么?

这是我的 htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
php_value memory_limit "64M" 
</IfModule> 

和索引页面配置

$config['index_page'] = '';

但是还是找不到404页面

http://hostname/blog <=== 404 page not found
http://hostname/index.php/blog <=== normal page show up

【问题讨论】:

标签: php .htaccess codeigniter config


【解决方案1】:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

这是用Codeigniter's user guide 编写的用于删除 index.php 文件的标准内容,您可以在其中添加其他规则。

【讨论】:

    【解决方案2】:

    在应用程序根目录中拥有 .htaccess 文件以及 index.php 文件。 (检查 htaccess 扩展是否正确,Bz htaccess.txt 对我不起作用。)

    并将以下规则添加到 .htaccess 文件中,

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

    然后在你的 application/config/config.php 文件中找到下面一行

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

    将变量设置为空,如下所示。

    $config['index_page'] = '';
    

    就是这样,它对我有用。

    如果它不起作用,请尝试将以下变量一一替换为这些参数('AUTO'、'PATH_INFO'、'QUERY_STRING'、'REQUEST_URI'和'ORIG_PATH_INFO')

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

    【讨论】:

      【解决方案3】:
      RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
      

      应该是:

      RewriteRule ^(.*)$ /index.php/$1 [L]
      

      请参阅http://ellislab.com/codeigniter/user-guide/general/urls.html 和标题为“删除 index.php 文件”的部分 您需要使用相同的 RewriteRule,但您拥有的 RewriteConds 很好。

      【讨论】:

      • RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php/$1 [L] php_value memory_limit "64M" 我更改了我的 htaccess 仍然找不到 404 页面 :(
      • 删除 IfModule 标记只是为了确保在服务器上什至启用了 mod_rewrite。
      • 为了安全起见,在文件中放入一些随机的垃圾文本,如 dghdkhgksdhkg 并保存。如果它没有出现 500 服务器错误,那么您的 htaccess 文件甚至没有被读取。
      猜你喜欢
      • 1970-01-01
      • 2011-10-09
      • 2017-07-05
      • 1970-01-01
      • 2011-10-06
      • 2012-12-30
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多