All the pages on the website have a structure which is given by HTML. HTML provides the structure to content, text, tables, headings, and lists on the webpage that makes the page easy to read. While saving an HTML document it has an extension as .html. Therefore, the URL of the website have a .html extension. The .html extension can be easily removed by editing the .htaccess file.
.htaccess file: The .htaccess file is created with a Text Editor like Notepad. It is a simple ASCII file that lets the server know what configuration changes are to be made on a per-directory basis.
Note: The .htaccess is the full name of the file. It is not file.htaccess, it is simply .htaccess.
Removing .html Extension: To remove the .html extension from a URL. For example:
You have to follow these steps:
- Log in to cPanel account.
- In the Files section, click on the File Manager icon.
- Click on the Settings Button in the top right corner.
- If you want to make changes in the Primary Domain then Click on the radio button next to the Web Root. If changes are to be made on Other Domains, then Click the dropdown menu and find the domain in which changes are to be made.
- Remember to check the checkbox next to Show Hidden Files. Now click the Save Button to return to the File Manager window.
- Now you are in the Root Folder of the domain which you have selected to make changes. Search for the .htaccess file and right-click on it. Click on the Edit option in the menu. You can now add code to the .htaccess file.
- Add the following code inside the .htaccess file:
- Click on the Save Changes Buton and then on Close Button.
You can now link any page inside the HTML document without needing to add the extension of the page as no extension will be visible now in the URL of the website.
<a href="http://example.com/image" title="image">image</a>
The search engine may index these pages as duplicate content, to overcome this add a
<canonical> meta tag in the HTML file.
<link rel="canonical" href="https://example.com/blog/first-blog" />
- How to remove extension from string in PHP?
- Why to use .html instead of .htm extension?
- How to redirect a page to another page in HTML ?
- How to Remove URL from Printing the Page ?
- How to get the title of an HTML page ?
- How to add Google map inside html page without using API key ?
- How to use Meta Tag to redirect an HTML page?
- HTML Course | First Web Page | Printing Hello World
- How to minify HTML code of PHP page ?
- Understanding "static" in "public static void main" in Java
- Understanding storage of static methods and static variables in Java
- How to get title of current HTML page using jQuery ?
- HTML | Responsive full page image using CSS
- How to design Meet the Team Page using HTML and CSS ?
- Difference between static and non-static method in Java
- Difference between static and non-static variables in Java
- How to select all visible or hidden elements in a HTML page using jQuery ?
- How to display search result of another page on same page using ajax in JSP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet