Disable index.php at the end of a URL

Asked by:
BulletTimeGuide / 5 Points
2012-04-01 6:52 am EST
Website Troubleshooting
When I typed the url of my site, be it the root or any folders of the site, the words "index.php" is automatically appended to the address:

For example,
when I type "www.mysite.com" it returns "www.mysite.com/index.php";
and when I type "www.mysite.com/folder" it returns "www.mysite.com/folder/index.php".

I would just like to disable this and have the url display what I typed.

Update: Let me clarify this. I am not trying to hide the extension, I am totally fine if a visitor knows the exact path to a file. The issue is that I would like to return the visitor with a 403 if he/she types "www.mysite.com/folder" instead of a 404 for "www.mysite.com/folder/index.php" (auto appended), because that file simply does not exist.

To ask this user for more information, please first login.

To submit an answer, please login.

Best answer chosen by User


1,846 Points
2012-04-06 1:47 pm EST
Hi BulletTimeGuide,

After quite a bit of debugging, I believe we finally figured out what was causing the issue with /index.php automatically being added to your URLs, and a 404 resulting instead of a 403.

The code doing this was somewhere within your public_html/.htaccess file. We proved this as when we disabled this file, the issue resolved itself. After narrowing down which file was causing the issue, we ultimately came to the following resolution (which you can see in your public_html/.htaccess file)

This was the problematic line of code:
RedirectMatch 301 (.*)\.html$ http://www.bullettimeguide.com$1.php

We couldn't find much information online regarding RedirectMatch, so we modified the code to instead use RewriteRule. The new line of code is:

RewriteRule ^(.*)\.html http://www.bullettimeguide.com/$1\.php [R=301,L]

... and the ultimate change you'll see is:

# This is the original line of code
# RedirectMatch 301 (.*)\.html$ http://www.bullettimeguide.com$1.php
# This is the updated code
RewriteRule ^(.*)\.html http://www.bullettimeguide.com/$1\.php [R=301,L]

Please be sure to test your website and let us know if you see any other issues. We had to clear our browser's cache throughout the testing, so you may need to do as well.

- Brad

To submit a comment on this answer, please first login.



13,688 Points
2012-04-02 9:15 am EST
Hello BulletTimeGuide,

Great question about hiding file extensions. You could try using the MultiViews directive in .htaccess like, this, but since some of your files are in directories with the same name as the files, I'm not sure if this would work correctly. You can certainly try it to see if you get the results you are looking for. Here is the code to place in your .htaccess file (make a backup of your current .htaccess file first before replacing that code with the following).

RewriteEngine on
Options +MultiViews

The other option is to use the following in your .htacess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Please let us know if you have any additional questions or need further assistance.


Christi N.

To submit a comment on this answer, please first login.

Want to share this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!

Help Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

Get help with your questions from our community of like-minded hosting users and Web Hosting Hub Staff.

Not a Customer?

Get web hosting from a company that is here to help.