Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect and remove index.php in Codeigniter [duplicate]

I'm using below htaccess to remove index.php from my url in Codeigniter.

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

The problem is that user can still use below code to access the method :

http://example.com/index.php/controller/method

How can I redirect them to url without index.php or send them to an error page if they add index.php ?

like image 986
user181892 Avatar asked May 25 '26 03:05

user181892


1 Answers

RewriteEngine On

RewriteRule ^index.php/(.*)$ /$1 [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

first rule redirects user non index.php site perminantly then it comes to your second rule and bingo.

like image 103
rcpayan Avatar answered May 26 '26 16:05

rcpayan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!