0

How can I never show index.php? For example, all requests to
site.com/index.php/controller are redirected in the browser address bar to
site.com/controller?

My current .htaccess removes index.php but when a user directly types site.com/index.php/controller they are still shown that address in the address bar as opposed to site.com/controller

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

NOTE: Before flaming, I have checked lots of .htaccess threads that solve redirecting index.php but I haven't found one to never show index.php. Here are a few...
Not Show index.php in subdirectory
remove index.php in codeigniter

1
  • Anyone able to shed light on this? Any help is much appreciated. Thanks. Commented Dec 5, 2011 at 15:12

3 Answers 3

0

Try adding the following to your .htaccess file in the root of your domain

RewriteEngine On RewriteBase / #if you get a request for this /index.php/controller RewriteCond %{REQUEST_URI} ^/index.php/controller$ #redirect to just controller RewriteRule . controller [R=301,L] 

If you need this to work for any path_info use the rule below instead

RewriteEngine On RewriteBase / #if you get a request for this /index.php(any-path) RewriteCond %{REQUEST_URI} ^/index.php/(.+)$ #redirect to any-path RewriteRule . %1 [R=301,L] 
Sign up to request clarification or add additional context in comments.

4 Comments

I think site.com/index.php/controller was just an example... he surely needs placeholders.
I have tried this but with no luck. Additionally I am working with the Codeigniter framework but I don't believe that would make a difference. Thanks but any other ideas? And yes on the placeholders.
What exactly isn't working? You're not getting redirected or you're getting a 500 Internal Server Error?
I am not being redirected. If I access site.comp/index.php/controller that remains in the address bar as opposed to being taken to site.com/controller. Thanks for the help and any ideas are appreciated to solve this.
0

Try:

RewriteEngine On RewriteBase / RewriteRule ^index.php(.*)% ^/$1 [QSA,R] 

I have not tested this, but as I understand it, it will take an URL with index.php as the filename (regardless of anything following it) and redirect it to /(.*) (i.e. anything that followed index.php in the original request). The QSA flag appends the query string, and R makes it a hard Redirect rather than just rewriting the URL on the current request.

Comments

0

For anyone looking for a more generalized solution:

Options +FollowSymLinks -MultiViews #Disallow listing contents of subfolders Options All -Indexes # Turn mod_rewrite on RewriteEngine On RewriteBase / # If index or index.php requested, strip and redirect RewriteCond %{THE_REQUEST} index(\\.php)? RewriteRule ^index(\\.php)?$ http://yourdomain.com/ [R=301,L] ## Part 1 ## hide .php extension # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L,NC] ## Part 2 - handle incoming that lacks extension (except for existing folders) ## To redirect /dir/foo to /dir/foo.php, (skip for admin or user dirs) RewriteRule ^(admin|user)($|/) - [L] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.