【问题标题】:While removing index.php from url in codeigniter, i am getting following error .Not Found The requested URL was not found on this server从codeigniter中的url中删除index.php时,我收到以下错误。未找到在此服务器上找不到请求的URL
【发布时间】:2021-02-03 23:41:29
【问题描述】:

从 URL 中删除 index.php 时,我收到一个错误 Not found

来自:- http://localhost/Inspire/index.php/welcome/dashboard

到这里

http://localhost/Inspire/welcome/dashboard

.htaccess

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



config.php



$config['index_page'] = ''; 

【问题讨论】:

  • 能否请您告诉我们您尝试从哪个 URL 重定向到哪个 URL,以便更清楚地了解
  • 请马上回答问题。
  • $config['uri_protocol'] = "REQUEST_URI" 用这个改变 AUTO
  • 仍然出现同样的错误
  • 你在哪里创建 .htaccess 文件??

标签: php .htaccess codeigniter codeigniter-4


【解决方案1】:

Codeigniter 4 有两个不同的 .htaccess 文件,你需要更改 public 文件夹中的一个:

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

【讨论】:

    【解决方案2】:

    我不得不换线:

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

    从公用文件夹中的 htaccess 文件到:

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

    【讨论】:

    • 对于基于 linux 的服务器仍然需要 QSA
    • 出于某种原因,我在我们的 Debian 服务器上不需要它。你能解释一下它的含义吗?
    【解决方案3】:

    根据您的评论它在应用程序文件夹中,所以它是错误的。 您应该在根网站文件夹中创建它。

    步骤:-1 转到您的 CodeIgniter 根文件夹并创建 .htaccess

    Path:
    Your_website_folder/
    .htaccess <——— this file
        application/
        assets/
        system/
        index.php
    

    .htaccess文件中写入以下代码

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

    步骤:-2 打开文件夹application/config 并打开文件config.php。在config.php文件中查找并替换以下代码。

    //find the below code   
    $config['index_page'] = "index.php" 
    //replace with the below code
    $config['index_page'] = ""  
    

    【讨论】:

      猜你喜欢
      • 2019-04-18
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 2014-11-28
      相关资源
      最近更新 更多