CodeIgniter使.htaccess为index.php返回404

时间:2016-09-03 15:55:54

标签: php .htaccess codeigniter http-status-code-404

以下是我的.htaccess文件,用于从我的CodeIgniter项目网址中删除index.php

<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>

这设法添加其他方式来导航index.php以外的网址,使这些网址合法:

my-project/index.php/home

my-project/home

如何重写.htaccess以便模式的所有网址

my-project/index.php/*

会返回404吗?

1 个答案:

答案 0 :(得分:1)

更好的解决方案是设置.htacces规则,将所有请求重定向到不包含index.php的网址。检查一下:

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/。{/ em> 免责声明2.似乎已经注释掉了,但这取决于网站上的编辑,代码将按原样为您工作。只是c / p。

Credits