【问题标题】:How to remove index.php from url in codeigniter?如何从codeigniter中的url中删除index.php?
【发布时间】:2016-01-26 11:10:24
【问题描述】:

以下代码在我的 .httaccess 文件中。

#write your project folder name as rewritebase
RewriteBase /Codeignitor3D/

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

它给出了 500 内部服务器错误

【问题讨论】:

标签: php codeigniter


【解决方案1】:

试试这个规则:

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

在您的config.php 文件中,

//Find   
$config['index_page'] = "index.php" 
//and replace it with
$config['index_page'] = ""

【讨论】:

    【解决方案2】:

    从 url codeigniter 中删除 index.php 的步骤:

    配置更改:转到“application/config/config.php”

    找到下面的代码:

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

    替换为以下代码:

    $config['index_page'] = '';
    

    .htaccess 更改:如果您没有任何 htaccess,请创建新的并将其放在您的根目录中。

    注意:如果您在子目录中有 codeigniter,请将 RewriteBase / 更改为 RewriteBase /subdir/

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

    现在打开您的网站页面,您会发现没有 index.php 的干净 url。所以你的所有网址看起来像http://example.com/controller/method。现在对 index.php 的任何 HTTP 请求都将被视为对 index.php 文件的请求。

    如果仍然存在问题:需要再应用一项配置更改。 转到“应用程序/config/config.php” 找到下面的代码

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

    用下面的代码替换

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

    现在您已经完全完成了从 url codeigniter 中删除 index.php 并在 codeigniter 中获取干净的 url。

    【讨论】:

    • @ParasDalsaniya 最后,将这一行 RewriteRule ^(.*)$ index.php/$1 [L,QSA] 更改为 RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    【解决方案3】:
    • 确保已安装并启用 mod_rewrite
    • 确保 apache 的站点配置文件允许使用 .htaccess
    • 检查 apache 的错误日志以及 PHP 的错误日志,因为你得到 500

    评论http://www.codeigniter.com/user_guide/general/urls.html

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 2015-10-24
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2012-09-21
      相关资源
      最近更新 更多