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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With