0

I've managed to remove the need for typing index.php in my urls, but it is still possible to do so. I don't want that and want to prevent users to be able to access my application via urls like /index.php/home or /index.php/contact or even /index.php.

Does anyone know how to accomplish this?

3 Answers 3

1

In you .htaccess write in the top

DirectoryIndex my_new_index.php

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

Rename your index.php file to my_new_index.php

Sign up to request clarification or add additional context in comments.

5 Comments

So you're suggesting to create an unguessable obscure directory index name so users won't be able to guess index.php?
I'm the OP. :) Okay, I see how this would work, but it's kind of "security through obscurity", isn't it?
@Kriem if it will be other than index.php you could block from inside php but unless its directoryindex i dont see any option other than rename
@Kriem me also using this way.
Accepted as answer as it kind of fixes it. Though I'm not happy with the solution. :(
0

Exactly. Here's an example:

RewriteRule    ^foo\.html$  bar.html

Or you can use variables like so:

^hotsheet/(.*)$  http://www.tstimpreso.com/hotsheet/$1

Comments

0

If you're using Apache, then just setup a rewrite rule to redirect users from index.php to /

RewriteRule ^/index\.php$ /
RewriteRule ^/index\.php/(.*) /$1

3 Comments

My reqrite rule: RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] - I'm still able to access index.php though.
Put this rewrite rule above your current one.
this will cause infinity loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.