CodeIgniter使.htaccess对index.php返回404


CodeIgniter make .htaccess return 404 for index.php

这是我从CodeIgniter项目url中"删除index.php"的.htaccess文件。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index'.php|images|media|assets|common|themes|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

这设法添加了另一种方法导航url,而不是index.php使这些url都合法:

my-project/index.php/home

my-project/home

我如何重写.htaccess,使模式

的所有url
my-project/index.php/*

将返回404?

更好的解决方案是设置.htacces规则,将所有请求重定向到没有index.php的url。检查这个:

RewriteEngine On
RewriteBase /codeigniter/
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index'.php [NC]
RewriteRule (.*?)index'.php/*(.*) /codeigniter/$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /codeigniter/index.php/$1 [L]

免责声明1。如果在根目录中,在看到/codeigniter/的地方只留下/免责声明2。似乎被注释掉了,但这取决于编辑在这里的网站上,代码将为您工作。就c/p。