URL Rewrite Using .htaccess File (Removing Page Extensions)

Importance of URL Rewrite or URL Masking

Very often you need to rewrite your website URL to make it search engine friendly. You may need to remove file extension from the pages.

Lets say you have a page named "services.aspx", If you look into the page then you might not get a proper idea what type of content your page is representing. Exactly the same way Search Engines also look in the pages and page names. So its very important to give a specific and user and/or SEO friendly URL names.

If we consider the above page then lets make it a bit user friendly by changing what it is representing actually. Lets change it to "seo-services-in-india.aspx", now you can see this name actually means something to users and/or Search Engines.

Another thing its a better to have pages with no extension, but you know its impossible to miss the file extension of a page (ie. .php, .html, .jsp, .aspx). So what you need you need to force the browser to render the "seo-services-in-india.aspx"  under the name of "seo-services-in-india".

In one of my previous article I have explained how to rewrite your website URL in C#(.NET). Here I will show you a simple example of achieving this using the .htaccess file.

URL Rewriting through .htaccess File

In my previous article on URL Rewriting, we have achieved the same goal by giving the dummy page name according to our choice that does not depend on the real page name.

e.g we have rewritten a URL from "contact.aspx"  to "my-contect-details", where the page name actually changed from one to other programatically. But here we will not change it but we will remove the extension only.

 <IfModule mod_rewrite.c>
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^([^\.]+)$ $1.html [NC,L]
     RewriteRule ^([^\.]+)$ $1.aspx [NC,L]
     RewriteRule ^([^\.]+)$ $1.php [NC,L]
     RewriteRule ^([^\.]+)$ $1.jsp [NC,L]

Now put the above code into your .htaccess file, and this will remove all the .html extensions from all your pages automatically. and the pages can be rendered without a file extension of  ".html", ".aspx", ".php", ".jsp"
Happy Coding...


  1. However with the passage of time, the trend is changing and celebrities
    are introducing their own line of dresses. White metal is the most chosen metal because it beautifully complements any skin tone
    and brings out the beauty of gown or furnish.
    The females are most involved with these handbags which are trendy and suitable to their lifestyle.

    Also visit my webpage Celebrity dresses 2014

  2. I'm not sure exactly why but this weblog is loading incredibly slow for me.
    Is anyone else having this issue or is it a issue on my end?
    I'll check back later on and see if the problem still exists.

    Here is my blog hair products by Loreal

  3. That is very interesting, You're a very professional blogger.
    I've joined your feed and stay up for seeking extra of your great post.
    Also, I've shared your web site in my social networks

    Feel free to surf to my web-site: bmw Car

  4. I don't know if it's just me or if perhaps everyone else experiencing
    issues with your website. It appears as though some of the text in your content are running off the screen.
    Can somebody else please provide feedback and let me know if this is happening to them too?
    This might be a problem with my internet browser because I've had
    this happen previously. Cheers

    Feel free to visit my website; bistro md