Having clean and user-friendly URLs is essential for improving website aesthetics, user experience, and SEO. If your website pages end with .html (e.g., example.com/about.html), you can remove the .html extension and access the page simply as example.com/about without affecting the functionality. This guide explains how to achieve this using .htaccess in cPanel.
Step-by-Step Guide to Removing .html Extensions in cPanel
Step 1: Log in to cPanel
- Open your web browser and go to
yourdomain.com/cpanel. - Enter your username and password.
- Click Login to access the cPanel dashboard.
Step 2: Open File Manager
- In cPanel, navigate to the Files section.
- Click on File Manager.
- Open the
public_htmlfolder (or the folder where your website is stored).
Step 3: Enable Hidden Files
- Click on the Settings button (top-right corner).
- Check Show Hidden Files (dotfiles).
- Click Save to display all hidden files, including
.htaccess.
Step 4: Locate or Create .htaccess File
- Look for a file named
.htaccessinsidepublic_html. - If the file exists, right-click on it and choose Edit.
- If the file doesn’t exist:
- Click + File (top-left corner).
- Name the file
.htaccess(include the dot at the beginning). - Click Create.
Step 5: Add Rewrite Rules to .htaccess
Open the .htaccess file and add the following lines at the bottom:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)$ $1.html [L]
Step 6: Save the Changes
- Click Save Changes.
- Close the editor.
Step 7: Test Your Website
Open your browser and try accessing your pages without
.html. For example:https://yourdomain.com/aboutinstead of:
https://yourdomain.com/about.html- If everything works correctly, your
.htmlpages should now load without the extension.
Step 8: Redirect Old .html URLs (Optional)
If you want to redirect old .html URLs to their new format (so about.html redirects to /about automatically), add this extra rule in .htaccess:
RewriteCond %{THE_REQUEST} \s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]
By following this guide, you’ve successfully removed the .html extension from your URLs, making them cleaner and more SEO-friendly. If you face any issues, clear your browser cache or test using Incognito mode.
Let me know in the comments if this guide helped you or if you have any questions!
Leave a comment
Your email address will not be published. Required fields are marked *