【问题标题】:CodeIgniter make .htaccess return 404 for index.phpCodeIgniter 使 .htaccess 为 index.php 返回 404
【发布时间】:2017-01-11 12:51:44
【问题描述】:

这是我的 .htaccess 文件,用于从我的 CodeIgniter 项目 URL 中“删除 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 以外的 URL,使这些 URL 都合法:

my-project/index.php/home

和

my-project/home

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

my-project/index.php/*

会返回 404 吗?

【问题讨论】:

  • 我能问一下您为什么要这样做吗?允许某人将index.php 添加到 URL 中应该没有安全风险......如果他们甚至出于某种奇怪的原因考虑这样做的话。
  • @Sparky 它对我来说看起来很丑。底线。切割并晾干。

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


【解决方案1】:

更好的解决方案是设置.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。

Credits.

【讨论】:

  • 谢谢@Tpojka!你介意检查my other question吗?我认为这也与.htaccess 有关
猜你喜欢
  • 1970-01-01
  • 2013-10-21
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
  • 2019-04-06
  • 2017-08-07
  • 1970-01-01
  • 2016-05-13
相关资源
最近更新 更多