skip to Main Content

I’m learning HTML, and I can’t figure out why some websites don’t have a .html extension on their webpage.
Example: no html extension
Example: html extension
Anyone know how I can make it look like that there is no extension? Is it safer than the other method?

I tried creating a file without an html extension, but it only showed text instead of html.

Thanks for any help!

5

Answers


  1. By default, every HTML file has to have the correct extension like example.html to be able to be rendered by the browser.

    If you remove the extension and open it in your browser using file protocol (file://.../example) it will only show its content as text, without rendering it as an HTML file.

    To render an HTML file without needing the extension, you need to serve it through an HTTP server. This server can be created using back-end technologies like PHP, Node.js, Python Frameworks, C++, Java, and Java Frameworks such as Spring Boot, etc. When serving your HTML files through a HTTP server you can define which URL serves what content. For example when a request hits the URL http://localhost/example you can write code to respond to this request with an HTML file, your example.html file. This way, the browser will show a URL of http://localhost/example but it (the server) will serve you with an HTML file.

    Login or Signup to reply.
  2. When you visit a webpage (which is different from simply just opening an .html file on your computer), the server looks at the URL you gave it in the address bar, and sends your browser some chunk of text based on that URL. If the response from the server is intended to be an HTML page, then the server will include along with the response a header that tells your browser that the text it just received needs to be processed and displayed as a .html file.

    Because a server is a computer program, and web developers have incredible freedom when developing a website, the server can send you anything it wants when you give it a URL. You can program a website to send back an image of a donkey when you give it a URL of /hello.html if you want to.

    Some web developers give all the URLs on their site a .html extension for various reasons, some do it for old search engine optimization (modern search engines don’t care), and some simply do it because of preference.

    The reason your browser requires a .html extension when you open a .html file on your computer is that otherwise, the browser won’t know what kind of text it is. As mentioned before, web servers send along a “header” with the response to your browser when you visit a page on the internet so including the .html extension in the URL is unnecessary.

    Login or Signup to reply.
  3. In general, the presence or absence of file extensions in website URLs serves different purposes:

    With extensions (e.g., ".html"):

    • Websites with URLs ending in ".html" typically serve HTML files directly to the browser.
    • These URLs indicate that the web server is delivering a specific HTML file to display.

    Without extensions:

    • Websites with URLs not ending in any extension may employ URL rewriting or routing techniques to determine what content to show in the browser.
    • Multiple possibilities exist for what’s happening behind the scenes:
      1. The server may still serve an HTML file but hides the extension for cleaner URLs.
      2. The server might dynamically generate content using server-side scripting languages like PHP, Python, Node.js, etc. In this case, there may be no fixed file with an extension.
      3. URL rewriting could be in use, showing a user-friendly URL like example.com/questions/ask while the actual file on the server might be something like show_recent_questions.php. This file extension is not exposed to the browser and neither is the original file name.

    The URL ending in .html doesn’t necessarily mean it was a static HTML page, since a rewrite rule could make any dynamic content also end w/ an extension of ".html".

    Also as @user3163495 mentions, you can also check the header information for additional details.

    Login or Signup to reply.
  4. That is because most websites these days use a router (usually with a framework).

    Modern websites need a database, authentication system, and … which can not be done using pure HTML and CSS. For these purposes, we need a server-side language to be able to get data from the database, authenticate users, and … like php language. When we are creating a website using PHP or any other server-side language, we usually like to create a router, which manages URL (website address) like https://example.com/slug1/slug2/...
    We call these parts slug. Which are separated by /. And yes, it is not so good to show the name of the file that is hosted on a server like https://example.com/login.html.

    So in a standard website, we manage url by a routing system and define slugs and the content that should be shown for each URL. But these days we do not create a routing system ourselves. There are a lot of frameworks like Laravel for PHP, that have built-in routing systems and you just define the URL for each page. It is more standard and meaningful. But if you are creating a simple website using pure HTML, that’s okay. I just wanted to say most websites are created by different frameworks that handle URLs themselves.

    That’s why you cannot see the url. When you run an html file in your browser, in the browser address bar, you see the html file address in your local machine, and when you upload host it, the filename and extension will be shown, like example.com/home.html, but as I said modern websites are created using a framework, Laravel, React, Vue and …

    Login or Signup to reply.
  5. One thing not mentioned in the other answers is that you can easily create URLs without an extension (at least on Apache) by calling the file index.html or index.php (or another name other than index if the server is so configured, such as home). So if your home page is mysite.com/index.html, the URL will just be mysite.com for your home page. If you wanted the URL to be mysite.com/about/, you could put your about content in another index.html file in an /about/ folder. So mysite.com/about/index.html will show in the browser as mysite.com/about/.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search