CodeIgniter 为 index.php 生成 .htaccess return 404
CodeIgniter make .htaccess return 404 for index.php
这是我从我的 CodeIgniter 项目 URL 到 "remove index.php
" 的 .htaccess
文件。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond !^(index\.php|images|media|assets|common|themes|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
</IfModule>
这成功地 添加了另一种方式 来导航 index.php
以外的 URL,使这些 URL 都合法:
my-project/index.php/home
和
my-project/home
如何重写 .htaccess
以便模式的所有 URL
my-project/index.php/*
会 return 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/ [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/ [L]
免责声明 1. 如果您在根目录中,请在看到 /codeigniter/
. 的任何地方留下 /
免责声明 2. 似乎被注释掉了,但这取决于现场编辑,代码将按原样为您工作。只是 c/p.
这是我从我的 CodeIgniter 项目 URL 到 "remove index.php
" 的 .htaccess
文件。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond !^(index\.php|images|media|assets|common|themes|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
</IfModule>
这成功地 添加了另一种方式 来导航 index.php
以外的 URL,使这些 URL 都合法:
my-project/index.php/home
和
my-project/home
如何重写 .htaccess
以便模式的所有 URL
my-project/index.php/*
会 return 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/ [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/ [L]
免责声明 1. 如果您在根目录中,请在看到 /codeigniter/
. 的任何地方留下 /
免责声明 2. 似乎被注释掉了,但这取决于现场编辑,代码将按原样为您工作。只是 c/p.