2

When we make HTML pages, we generally save it with a .htm or .html extension. But most webpages on the internet have extensions like .com or .org, for example, https://example.com. How do these pages work?

3
  • .org in en.wikipedia.org is NOT an extension, please do not use this term, even if widely used. It is one of the label of the domain name, and since it is at the extreme right and since DNS is right to left writing basically, it is called the Top Level Domain or TLD for short. Aug 20, 2019 at 14:27
  • On the web, filename extensions should not matter, if things are properly done. See "What to leave out" in w3.org/Provider/Style/URI (but the whole document is a very good read) Aug 20, 2019 at 14:29
  • you can use .htaccess and URL rewriting. This is part of server configuration.you can't do it with only .html extension.Refer following site:en.wikipedia.org/wiki/Rewrite_engine
    – AjayGohil
    Nov 12, 2020 at 4:57

2 Answers 2

2

There are several ways to achieve this:

  1. Create an index.html inside root folder of your hosting and open your domain ie. http://example.com, you can see the output from index.html on http://example.com

  2. You can tell your server using .htaccess to display the desired file when someone opens your domain.

-1

Create your index.html file. You will see when you publish that it will say 'example.com/page.html'. To remove the .html you need to create a .htaccess file in your root folder. Within that .htaccess file paste this code:

#Removes file extentions from URL
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]

This also removes .php file extensions.

It's good to know that if you want HTTPS instead of HTTP, you also use the same .htaccess file for this.

3
  • This rewrite URLS with no periods that don't have a corresponding file in the file system to internally look for a .php file. Otherwise for such URLs that do have a file, it adds a .html extension. (Your RewriteCond only applies to the very next rule, not to both rules.) These rewrite are very broken and nobody should be using them. They also don't solve the whole problem. They could allow some extensionless URLs to work, but they don't remove extensions from existing URLs or change any links within your site that contain URL extensions. Feb 10, 2020 at 10:42
  • I'm not sure how you can say that, because when I use it on my websites it removes the .html and .php from the url. So it does work.
    – Delboy
    Feb 11, 2020 at 12:11
  • I would recommend changing the condition to RewriteCond %{REQUEST_FILENAME}.php -f and adding a second condition before the .html rule: RewriteCond %{REQUEST_FILENAME}.html -f. I think those would work, if you could test them and update your question. It would also be ideal to include any code you have for redirecting away from the .php and .html URLs and to explain how you link in your pages. Feb 11, 2020 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.