【问题标题】:CodeIgniter - How to hide index.php from the URLCodeIgniter - 如何从 URL 中隐藏 index.php
【发布时间】:2011-02-15 18:15:08
【问题描述】:

这就是我的.htaccess 的样子。 .htaccess 位于/www/scripts 目录中,该目录是codeigniter 的system 目录的父目录,并且还包含index.php。我在我的 Apache 2.2.x 中启用了mod_rewrite。这是在 Ubuntu 9.10 服务器上。

我关注了这个link,但它不起作用。我需要在 apache2 中做些什么,任何特定的配置才能使其正常工作吗?

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

【问题讨论】:

标签: php .htaccess codeigniter url mod-rewrite


【解决方案1】:

使用这个:

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

【讨论】:

  • 我希望你在你的服务器中启用了 mod_rewrite
  • 是的,我已启用 mod_rewrite,我想我取得了一些进展,但现在我在 apache 错误日志中收到此错误,如果启用 .htaccess “由于可能的配置,请求超出了 10 个内部重定向的限制错误”
  • 您可能希望将此作为正确答案进行检查。这对其他用户来说会很容易。
  • RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ... 表示如果浏览器中指定名称的文件不存在,或者浏览器中的目录不存在则继续下面的重写规则
【解决方案2】:

只需将以下代码放入您的 .htaccess 文件中

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

来源:http://codeigniter.com/user_guide/general/urls.html

【讨论】:

    【解决方案3】:

    这是一个简单的解决方案。

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 

    【讨论】:

      【解决方案4】:
      猜你喜欢
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 1970-01-01
      • 2012-08-10
      • 2015-10-24
      相关资源
      最近更新 更多