在 codeigniter 中从 url 中删除 index.php 时,出现以下错误。未找到请求的 URL 未在此服务器上找到
While removing index.php from url in codeigniter, i am getting following error .Not Found The requested URL was not found on this server
从 URL 中删除 index.php 时,我收到错误消息 Not found
来自 :- http://localhost/Inspire/index.php/welcome/dashboard
至此
http:///localhost/Inspire/welcome/dashboard
.htaccess
RewriteEngine on
RewriteCond !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
config.php
$config['index_page'] = '';
根据您的评论,它在应用程序文件夹中,所以它是错误的。
您应该在根网站文件夹中创建它。
步骤:-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/ [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'] = ""
我不得不换行:
RewriteRule ^(.*)$ index.php/ [L,QSA]
从 public 文件夹中的 htaccess 文件到:
RewriteRule ^(.*)$ index.php?/ [L]
Codeigniter 4 有两个不同的 .htaccess 文件,您需要更改 public 文件夹中的那个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]
从 URL 中删除 index.php 时,我收到错误消息 Not found
来自 :- http://localhost/Inspire/index.php/welcome/dashboard
至此
http:///localhost/Inspire/welcome/dashboard
.htaccess
RewriteEngine on
RewriteCond !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
config.php
$config['index_page'] = '';
根据您的评论,它在应用程序文件夹中,所以它是错误的。 您应该在根网站文件夹中创建它。
步骤:-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/ [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'] = ""
我不得不换行:
RewriteRule ^(.*)$ index.php/ [L,QSA]
从 public 文件夹中的 htaccess 文件到:
RewriteRule ^(.*)$ index.php?/ [L]
Codeigniter 4 有两个不同的 .htaccess 文件,您需要更改 public 文件夹中的那个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]