Here is my .htaccess
file to "remove index.php
" from my CodeIgniter project URLs.
<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>
This managed to add another way to navigate URLs other than index.php
making these URLs both legal:
my-project/index.php/home
and
my-project/home
How do I rewrite the .htaccess
so that all URLs of the pattern
my-project/index.php/*
will return 404?
Better solution would be setting .htacces
rules to redirect all request to URLs without index.php
in it. Check this one:
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]
Disclaimer 1. If you are in root directory, leave just /
everywhere you see /codeigniter/
. Disclaimer 2. Seems like commented out, but it is up to editor here on site, code would be working for you as is. Just c/p.
Credits .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.