3

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 ?

user181892
  • 53
  • 1
  • 5
  • The duplicate marking of this question is incorrect. This is a follow-on case where the questioner wants to both acheive the removal of the index.php and also redirect any existing links/bookmarks to the new URL. The related question doesn't tell you how to do that second part - which is what the questioner is clearly asking about. – scipilot Oct 25 '15 at 05:34

1 Answers1

9
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.

rcpayan
  • 535
  • 3
  • 15