The .htaccess file is a hidden text file within your hosting account that can be very powerful. It is designed so that you can modify it to change the behavior of your website that normally would take higher access beyond your account. It acts as a liaison between your domain and the server and can perform many functions.

Lately there seems to be a trend where designers want to cloak their file extensions from their visitors. For example, they want the URL 'domain.com/index.html' to display as 'domain.com/index' for whatever reason. Some like the way it looks, others believe it helps with SEO, and others believe it is better for security. I am unsure the last two hold any bit of truth, however. This is a feature you can implement via your htaccess file. This article will guide you through doing so via your cPanel.

How to remove file extensions from display via htaccess

  1. Log into your cPanel
  2. Find the Files category and click on the File Manager icon.
    cpanel
  3. A popup box will appear. For the primary domain, click on the Web Root radio button. For addon domains, click on the dropdown and find your desired addon domain name. Be sure the checkbox next to Show Hidden Files is checked. Click the Go button to enter the File Manager.
    file-manager-show-hidden
  4. You should now be in the root folder of the domain you chose. Look for the .htaccess file and right click on it. This brings up a menu. Find and click on the Edit option. If you get a popup box, simply find and click the Edit button in the lower right corner to continue to the editor.
    file-manager-htaccess
  5. You are now in the text editor. As most sites are coded with either htm or php, we have include the code for both below.
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html
  6. Be sure to hit the Save Changes button in the upper right corner to save your new htaccess configuration. Your site should now display the address without the file extension.
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-04-26 1:13 pm
using this code i am not able to remove the extension from my code..
Staff
18,373 Points
2014-04-28 12:12 am
Hello Vijay,

We would be happy to assist you. Would you please reply with the code you have in your .htaccess so we can take a look?

Kindest Regards,
Scott M
n/a Points
2014-06-13 3:08 pm

dear sir there is a code utf-8  and page showing empity

 

thanks

n/a Points
2014-05-02 5:46 am

Hi Vijay, you're probably referring to a linked page if you're still seeing the file extension. Make sure you're links don't have .html or .php at the end of them:

<a href="/support/linkedpage.php">link text</a> is wrong, it will force the browser to display .php despite the rewrite engine in use.

<a href="/support/linkedpage">link text</a> is right, this will ask the browser to find this file, and with the rewrite engine it will find it and display it without the extension.

n/a Points
2014-07-11 7:08 pm

Hi there! A .htaccess file was not in my file manager, even after making sure I would be able to see hidden files, so I had to create one on my own. I am trying to remove extensions from my website using the two codes listed above (for .html and .php) and it is not working. This is the code I have:

 

Options +FollowSymLinks

Options +Indexes

RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^([^.]+)$ $1.php [NC,L]

 

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 

RewriteCond %{REQUEST_FILENAME}\.html -f 

RewriteRule ^(.*)$ $1.html

Staff
16,683 Points
2014-07-11 7:32 pm
Hello Brenna,

Sorry for the problems with the .htaccess file. In reviewing the code you provided, it does not match what was provided in the article above. Please go back and edit your .htaccess file so that it matches what Scott has provided for the re-write rules and it should work.

If you continue to have problems, please let us know.

Regards,
Arnel C.
n/a Points
2014-07-11 9:00 pm

I have edited my .htaccess file with the code above and it still does not work.

Staff
16,683 Points
2014-07-11 9:06 pm
Brenna,

Apologies for the problem with the .htaccess. However, without any information on your website, it makes it difficult for us to help troubleshoot the problem. Can you please provide a URL and a description of how we duplicate the problem you're seeing?

Kindest regards,
Arnel C.
n/a Points
2014-07-11 10:15 pm

The url that is working is creamilla.com/brenna.php, however, when you type in creamilla.com/brenna, you get a not found error. The complete code in my .htaccess is:

<Files .htaccess>order allow,deny deny from all </Files> 

suPHP_ConfigPath /home/creamilla/public_html 

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

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

Thank you.

Staff
18,373 Points
2014-07-13 1:33 pm
Hello Brenna,

Yes, that is correct, you will get a not found error. This is because the server needs to know what you are looking for specifically. Despite not showing the .php in the address bar, the file is still named brenna.php, there could also be brenna.htm and brenna.html file names, all being told not to display their extension. The server needs to know which one you want. In fact, if you do not put an extension at all, the server assumes you are looking for a subfolder named brenna. When visiting the site, either by code or typing directly, you must be specific. The removal of the extension is simply for aesthetics.

Kindest Regards,
Scott M
n/a Points
2014-07-13 3:23 pm

Oh, that makes sense. Sorry, I'm a complete newbie. What about for links? Is there any way I can direct from /brenna.php to just /brenna? I tried putting /brenna for a link and it displayed the not found error as well.

Staff
18,373 Points
2014-07-13 9:27 pm
Hello Brenna,

As far as the code for the link, you need to be specific (brenna.php, brenna.htm, etc) because the server is not so smart. The code in the .htaccess file should still take over and display it as example.com/brenna however so your visitors will never know the extension.

Kindest Regards,
Scott M
n/a Points
2014-07-13 10:26 pm

I put the .php at the end of the address in the link, however when I check it, it still goes to /brenna.php.

Staff
8,426 Points
2014-07-14 10:13 am
You may have old data cached in your browser. Try clearing your browser cache.
n/a Points
2014-07-14 12:18 pm

Thank for for the suggestion, Jeff. However, it doesn`t seem to have cleared up the problem.

Staff
18,373 Points
2014-07-14 1:36 pm
Hello Brenna,

You are correct, the code does not seem to work any longer. After more testing and experimenting with other sites recommendations (all of which did not work either), I finally found one that does work. I have tested it on my own server. Use this code below:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## 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]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]


Kindest Regards,
Scott M
n/a Points
2014-09-11 5:19 pm

Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / ## 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] ## To internally redirect /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L]

 

This code finally works... spent half a day finding it.

I found other examples but I'd have two versions of the same file whereas with this code I get only one version... THANK YOU SO MUCH

n/a Points
2014-07-14 1:45 pm

I entered that code into my .htaccess and the .php still shows when I click the link.

Staff
18,373 Points
2014-07-14 2:52 pm
Hello Brenna,

At this point you may want to check with your host as the above code is working on our servers. It is general code so it should work elsewhere but there could be something that is preventing it from working on the server on which you are located.

Kindest Regards,
Scott M
n/a Points
2014-07-16 4:30 am
Hello,
This artical is such a nice artical it will working on localhost very perfectly but when i test it on live server it is not working so plzzz help me..
how can i improve my code give any hint or link of refrence site..
thank u in advance..
I am waiting your reply..
Staff
18,373 Points
2014-07-16 7:50 am
Hello Arpita,

Please try the code below instead to see if it works for you:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## 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]


Kindest Regards,
Scott M

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
n/a Points
2014-07-17 2:15 am

Hello,

Thank you for a code but it is not working on localhost or live server..

error occures 404 not found it is page not found error..

plzz give me other examples..

 

Thank you for reply..

n/a Points
2014-07-17 1:10 am

Hello..

I am working on one project i face one problem related htaccess file..it will run perfectly in localhost but same code is not working on live server in my website..

here i smy code

Options +FollowSymLinksRewriteEngine on RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}\.php -fRewriteRule ^(.*)$ $1.phpI am use this code its run perfectly but not on server i waste my most of time in that but no result are there so plzz help me..

waitting for your reply what can i do for this problem.. :(

Thank you in advance..

Staff
8,426 Points
2014-07-18 9:31 am
Could you provide me with the URL that you are having trouble with?
n/a Points
2014-07-18 11:35 am

Hello JeffMa,

Yes ofcourse my url is this http://artocean.omexinfotech.com/index.php..

in this url i have problem this is run perfectly in localhost but problem is on live site..

plzz check it and give me suddestion..

thank you..

Staff
16,683 Points
2014-07-18 12:46 pm
Hello Arpita,

We're sorry that you continue to have problems with the removal of the file extensions. The code we have offered works on our servers. It may be different on yours. You may want to check this tutorial from a third party, as it might give you working option.

If it works for you, please let us know!

Regards,
Arnel C.
Staff
8,426 Points
2014-07-18 12:49 pm
We have confirmed that the code itself does work, but it looks like you are hosted with someone else that may be causing issues on their end. I recommend working with your hosting provider for more information.
n/a Points
2014-07-19 4:22 am

Hello JeffMa,

You are right my code is not problem but my hosting server has problem i check that on another server it will run perfectly..so no any issue

but i have another problem about remove query string from url

here is my code:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^service_id=([0-9]*)$
RewriteRule ^servicecnt\.php$ http://artocean.omexinfotech.c... [R=302,L]

code is work perfectly their output url is this:

http://artocean.omexinfotech.com/servicecnt.php/3?service_id=3

that is not correct i required only this not whole url

url http://artocean.omexinfotech.com/servicecnt.php/3

have idea to truncate last characters or any rule of that to remove so plzzzz suggest me...

thank you..

Staff
9,968 Points
2014-07-21 12:13 pm
Hello arpita,

It looks like your RewriteRule got cut off so we can't see the full code that you're using. If you wanted someone going to this URL:

http://example.com/servicecnt.php?service_id=5

To end up at this URL:

http://example.com/servicecnt.php/3

You would use this code:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^service_id=([0-9]*)$
RewriteRule ^servicecnt\.php$ /servicecnt.php/%1? [R=302,L]



The /servicecnt.php/%1? part of the RewriteRule should tell the server to redirect to /servicecnt.php/ followed by the service_id QUERY_STRING, and the ? at the end tells Apache to leave off that query string in the rewritten URL.

Please let us know if you had any further questions at all.

- Jacob
n/a Points
2014-07-22 12:16 am

Hello Jacob,

Your code nice but... url is not proper or 404 vpage not fount error is genrated when i use your code..

http://localhost/servicecnt.php/4  like this  in this url my project folder name is missing so url is not found..

http://localhost/art-ocean/servicecnt.php/4 my actual url is this when this url meet then no error occurs..

so give me modification in that code which is provide by you..

waititng for your reply..

Thank you..

n/a Points
2014-07-25 3:24 am

Hello Jacob,

Any Idea about my issue then plzzz tell me..

I am waiting for your reply..

Thank you very much in advance..

Staff
9,968 Points
2014-07-25 1:45 pm
Hello arpita,

I don't quite understand what you're trying to accomplish with your rewrite rules, are you sure that this is the best method for the scripts you're using? Perhaps if you could explain the purpose of your script it would be easier for us to recommend you something.

When relying on rewrite rules to do something your scripts are handling, you can occasionally run into problems in different server environments. This sounds like the problem you are currently having trying to take your site live.

For instance, if you wanted the URL http://localhost/art-ocean/servicecnt/4 to be a valid address. You could simply place a index.php file inside the directories /art-ocean/servicecnt/4.

Typically you'd remove the file extension of URLs like this guide explains for SEO purposes and to make them more human friendly, but not much can be derived from /art-ocean/servicecnt.php/4 and it still includes the .php extension in the URL which is what this article talks about getting rid of.

If you were getting a 404 error using my previous code example because it ends up redirecting you to:

http://localhost/servicecnt.php/4

Instead of going to where your script expects at:

http://localhost/art-ocean/servicecnt.php/4

Are you placing the .htaccess rules simply in your /public_html/.htaccess file? Or are you putting them inside the /public_html/art-ocean/.htaccess file?

You might need to change it to include the sub-directory if you're just placing the code in your main .htaccess file:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^service_id=([0-9]*)$
RewriteRule ^servicecnt\.php$ /art-ocean/servicecnt.php/%1? [R=302,L]



Please let us know if you have any further questions.

- Jacob
n/a Points
2014-07-26 1:59 am

Hello Jacob,

Thank you very much my url issue is solve i am soooo happy..

but that url design will be changed it may not display..

see i will send you..

so now what can I do plzz give me solution..

waiting for your reply..

here I attach my page..

Staff
9,968 Points
2014-07-26 10:45 am
Hello arpita,

Unfortunately your image wasn't attached successfully. In the future if you could simply place any screenshots or images you're trying to send us onto your website and then just provide a URL to them we can take a look for you.

- Jacob
n/a Points
2014-07-28 12:02 am

Hello Jacob,

Here i send my actual page with design and without rewrite url..

my design like this which i send you previous..

thank you for reply..

Staff
18,373 Points
2014-07-28 8:31 am
Hello Arpita,

Unfortunately images posted into the comments are not allowed and stripped by our server. You will want to simply upload the images to your server and then place a URL in the comment to that image. Then we can take a look for you.

Kindest Regards,
Scott M
n/a Points
2014-07-28 11:58 pm

Hello Jacob,

Here is my url http://artocean.omexinfotech.com/ourservices.php which design is not supported when I rewrite query string url..

Please check it and give me suggestion..

Thank you..

Staff
18,373 Points
2014-07-29 7:29 am
Hello Arpita,

I do see that the services are leading to 404 errors. Unfortunately other than the code we have given we do not know what your server needs. We are unable to test because you are not one of our customers so we have no access to the server, nor its configuration. With the code working in localhost, you can tell it is generally correct. You may need to ask your host if there is anything else needed as they seem to have a configuration that is interfereing.

Kindest Regards,
Scott M
n/a Points
2014-07-30 5:01 am

Hi scott,

Its ok but my code is correct then it is not issue i think my server has a problem when I upload it on client server then problem will be solved..

Thank you..

n/a Points
2014-08-27 1:50 am

Hello,

I have littel problem in wordpress dynamic menu..

My html page css is not working on wordpress dynamic menu so plzz help me..

here i attach one image..

You can here menu beside logo that menu is not proper space between 2 menu is not proper so i have to want make it proper so plzz help me...

 

Thank You..

Staff
18,373 Points
2014-08-27 10:41 am
Hello Arpita,

Unfortunately I do not understand what you are asking. Did you create your own CSS and want it to work in Wordpress? Did you modify existing css file in WordPress? Did you modify it in the WordPress back end?

Also, this particular article is about htaccess files and file extensions, so it is likely better to ask a new question instead of placing it in a non-relevant article so other people can also help.

And once again, images cannot be added to questions or comments. They are stripped out and do not display for anyone.

Kindest Regards,
Scott M
n/a Points
2014-08-28 12:14 am

Hello Scott,

Thamk you for reply..

n/a Points
2014-08-28 1:46 am

Hello Scott,

I want a rewrite url in htaccess..

I want open site with www and also without www so you have any idea about this so plzz share with me..

Plzz help me..

Thank You..

Staff
18,373 Points
2014-08-28 9:55 am
Hello Arpita,

When working with Wordpress, it will display in either www or non-www,whichever you choose. You can, however set the htaccess file to force either one you desire.

A quick search in our search bar up top brought up our article on forcing www or non-www for your site.

I hope that helps you,

Kindest Regards,
Scott M
n/a Points
2014-08-28 12:03 pm

Hello Scott,

Thank you very much for reply..

n/a Points
2014-09-01 2:55 pm

I agree Scott. I doubt this will give any SEO or Security benefit. It is a cute trick someone thought up that I believe will be problematic at best, especially for larger websites that have been around awhile. Nice that someone actually said it, instead of just writing an article that appears to be 100% backed by the writer. Good job.

 

Like you, I am seeing this more and more, but I can't help but think it is a mistake. I would definitely not use the trailing slash because it represents a directory. What about all of the links already pointing to your pages, that you have no control over? They actually do have SEO value. They will turn into 404 errors that Google and other search engines do not like. I believe you have to change all of your internal links. CSS files and images might stop working. It just seems to be a huge risk, especially for higher traffic website.

 

When is the last time you typed in a URL to a nested web file? Most use a link. Stores like Amazon do not do this and they dominate the web. My vote is for "NO!". There are plenty of other things more worthy of your time. Link building, Article writing, Micro data, Accessibility to name just a few.

n/a Points
2014-09-03 12:35 am
Article is excellent... and more helpful thing is that if we ask any question then we gave answer of them from your team so it is very helpful to us.

If I have other query about php or wordpress etc them I will ask question in this article?????

Thank you very much..
Staff
18,373 Points
2014-09-08 8:56 am
Hello Arpita,

Generally we ask that the comments and questions in an article relate to the article topic. You are more than welcome to ask a new question using the 'Ask a Question' link. This way other people that have the same question can also find it easily.

Kindest Regards,
Scott M
n/a Points
2014-09-05 7:50 am
pls send me a pdf for this....
Staff
18,373 Points
2014-09-08 8:59 am
Hello viralpatel,

Unfortunately we do not have pdf files of our articles. However, I will submit an idea to our team on creating specific pdf guides for certain topics. Thank you for that idea!

Kindest Regards,
Scott M
n/a Points
2014-09-06 8:13 am

Hi there.  I just did a copy and paste into the htaccess file and this code is not working.  

Here is a link sample.  http://www.youreunique.net/index?page=our_difference

I too, am a total newbie when it comes to webdesign.  My web guy was a friend and his mother passed away and he bascially disappeared.  We have already exhuasted our advertising/marketing/website budget for the year so any help that I can get will be great appreciated!  

Traci 

 

 

Staff
18,373 Points
2014-09-08 9:01 am
Hello Traci,

If you could reply with your exact code we are happy to test it on our server for you to see if it needs any tweaks.

Kindest Regards,
Scott M
n/a Points
2014-09-07 1:22 am

using this code i am not able to remove the extension from my code.

Staff
18,373 Points
2014-09-08 9:02 am
Hello Viral,

We are happy to take a look for you. Please reply with your code so we may see it.

Kindest Regards,
Scott M
n/a Points
2014-09-17 1:05 am

thank u for this coding.....this code is very usefull for hiding the extension in my site thank u.....

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

55 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

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

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!