Question

I'm creating a website for my personal needs. I have different pages like index.html, about.html, contact.html etc... The default way of showing them is mysite.com/index.html or mysite.com/contact.html

But is there any way to hide the extension part .html and just to show the url main texts like mysite.com/about/ or mysite.com/contact/ ??

Please advice me.

Was it helpful?

Solution

You have to use a URL rewrite engine, edit (or create) the .htaccess like that:

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

For more details: Remove .html from URLs with a redirect

OTHER TIPS

It's possible to show your page with mysite.com/about/

  1. You need to replace all file name to index.html
  2. Eg : about.html to index.html
  3. Add index.html to their respective pages, like

Before:

www/
|
|-about/about.html
|
|-contact/contact.html
|
|-etc/etc.html

After :

www/
|
|-about/index.html
|
|-contact/index.html
|
|-etc/index.html

Now when you hit the URL www.yourSite.com/about that page will be shown. (without about.html part)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top