Search

Remove .html Extension from URLs in cPanel

Remove .html Extension from URLs in cPanel

 

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

  1. Open your web browser and go to yourdomain.com/cpanel.
  2. Enter your username and password.
  3. Click Login to access the cPanel dashboard.

Step 2: Open File Manager

  1. In cPanel, navigate to the Files section.
  2. Click on File Manager.
  3. Open the public_html folder (or the folder where your website is stored).

Step 3: Enable Hidden Files

  1. Click on the Settings button (top-right corner).
  2. Check Show Hidden Files (dotfiles).
  3. Click Save to display all hidden files, including .htaccess.

Step 4: Locate or Create .htaccess File

  1. Look for a file named .htaccess inside public_html.
  2. If the file exists, right-click on it and choose Edit.
  3. 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

  1. Click Save Changes.
  2. Close the editor.

Step 7: Test Your Website

  1. Open your browser and try accessing your pages without .html. For example:

    https://yourdomain.com/about
    

    instead of:

    https://yourdomain.com/about.html
    
  2. If everything works correctly, your .html pages 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!

Fahim Muntashir

Fahim Muntashir

Fahim Muntashir, an aspiring Computer Science and Engineering graduate from North South University, Dhaka,Bangladesh with strong programming expertise and a solid command of computer and web technologies. Throughout the academic journey, he has excelled in various competitions, showcasing his skills and dedication to excellence. Beyond academics, he is passionate about photography and traveling, with his work exhibited both nationally and internationally in three different countries.

Leave a comment

Your email address will not be published. Required fields are marked *