【问题标题】:Codeigniter remove index.php from URL localhost:82/projectCodeigniter 从 URL localhost:82/project 中删除 index.php
【发布时间】:2019-03-02 17:18:45
【问题描述】:

我有网址

http://localhost:82/project/index.php/home

我想从上面的 url 中删除 index.php。

像这样:http://localhost:82/project/home

我用过很多解决方案

1) 我已经从 config.php 文件中删除了 index.php:

$config['index_page'] = '';

2) 更改 config.php 文件中的“uri_protocol”:

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

我的 htaccess :

RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

这里有高手解答我的问题吗?提前致谢。

【问题讨论】:

  • 您是否正确设置了base_url?和默认控制器?您遇到了什么错误。

标签: php codeigniter .htaccess


【解决方案1】:

使用这个 Codeigniter .htaccess 文件并将其安装到您的根应用。

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

喜欢这个...

project_name
    -application
    -assets
    -system
    -user_guide
    -.htaccess // like this one

【讨论】:

    【解决方案2】:

    尝试使用这个

    RewriteEngine on
    #RewriteBase /project/
    RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
    RewriteRule .* index.php/$0 [PT,L]
    

    我使用它并为我工作。 谢谢你

    【讨论】:

      【解决方案3】:

      在配置中设置你的基本 URL 为

      $config['base_url'] = 'http://localhost:82/project/'
      

      在你的 .htaccess 中,试试这个,我在我的 CI 项目中使用过这个。

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

      将此文件放在您的项目文件夹中。

      【讨论】:

        【解决方案4】:

        如果您使用的是 Apache 服务器,则必须启用 mod_rewrite。然后用下面的代码修改你的 .htaccess 文件。

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

        欲了解更多信息,请访问here

        尝试类似的问题here

        【讨论】:

          猜你喜欢
          • 2015-03-19
          • 2016-05-14
          • 2014-10-28
          • 2012-06-15
          • 2012-09-21
          • 2011-10-12
          • 2017-07-16
          相关资源
          最近更新 更多