How to remove .html from URL

I was adding a new events page to the milspousecoders.org website. When you view the URL (Uniform Resource Locator) it was showing the .html after the page. I didn’t like that. I thought it made us look amateurish. Being a web developer there is always a solution you can find on google and StackOverflow.  Here are step-by-steps instructions.

Access your cPanel for your website

Go to SETTINGS and click on  Show Hidden Files (dotfiles)

01

Create a new  .htaccess file in your public_html folder. 

02

Inside your .htaccess file add this.


RewriteEngine on
RewriteBase /
RewriteCond %{http://milspousecoders.org/} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://milspousecoders.org/ [R=301,L]

You will replace http:milspousecoders.org/ on line 3 and 8 with your website.

03

In your file where you have your index.html or file that has a .html extension change the  link to the name of the file without the .html.

I have an events.html page I want to link on the website.

<a href="http://www.milspousecoders.org/events">Events</a>

04

Voila! Your URL no longer has the .html extension.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s