How to Remove .html, .php, or Both from URLs

By James Wilson | Last updated on January 2, 2026

How to Remove .html and .php File Extensions from URLs

Having clean and user-friendly URLs is essential for improving website navigation and SEO. By removing file extensions like .html and .php, you can create shorter, more readable URLs that enhance user experience and look more professional. Additionally, search engines prefer concise URLs, which can contribute to better rankings.

In this guide, we’ll walk you through the step-by-step process to remove file extensions from URLs using .htaccess. Whether you want to remove only .html, only .php, or both, we’ve got you covered.

Here’s what we’ll cover:
βœ… How to remove .html file extensions
βœ… How to remove .php file extensions
βœ… How to remove both .html and .php extensions for a cleaner URL structure

By the end of this guide, your website URLs will look cleaner, more professional, and easier to remember! πŸš€

πŸ”Ή Step 1: Check if .htaccess Exists

Before making changes, ensure your website is running on an Apache server with mod_rewrite enabled.

  1. Go to your website’s root directory (e.g., public_html).
  2. Look for a file named .htaccess.
    • If it exists, edit it.
    • If not, create a new file named .htaccess.

πŸ”Ή Step 2: Remove .html from URLs

To remove .html extensions and make URLs cleaner, add the following code to your .htaccess file:

RewriteEngine On

# Redirect .html URLs to clean URLs (for SEO)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html\sHTTP [NC]
RewriteRule ^ %1 [R=301,L]

# Serve .html files without typing .html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

πŸ“Œ Example:

  • yourdomainname.com/about.html β†’ yourdomainname.com/about
  • yourdomainname.com/contact.html β†’ yourdomainname.com/contact

πŸ”Ή Step 3: Remove .php from URLs

To remove .php extensions, add this to your .htaccess file:

RewriteEngine On

# Redirect .php URLs to clean URLs (for SEO)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php\sHTTP [NC]
RewriteRule ^ %1 [R=301,L]

# Serve .php files without typing .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

πŸ“Œ Example:

  • yourdomainname.com/about.php β†’ yourdomainname.com/about
  • yourdomainname.com/contact.php β†’ yourdomainname.com/contact

πŸ”Ή Step 4: Remove Both .html and .php

If your website has both .html and .php files and you want to remove both extensions, use this:

RewriteEngine On

# Redirect .html and .php URLs to clean URLs (for SEO)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.(html|php)\sHTTP [NC]
RewriteRule ^ %1 [R=301,L]

# Serve files without .html or .php in the URL
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

πŸ“Œ Example:

  • yourdomainname.com/about.html β†’ yourdomainname.com/about
  • yourdomainname.com/about.php β†’ yourdomainname.com/about

Now that your URLs no longer require .html or .php, it’s essential to update all internal links throughout your website.

βœ… Manually Update Links – Go through your HTML, PHP, or database links and remove .html or .php where necessary.

βœ… Update Navigation Menus – If your website has navigation menus or buttons linking to pages with file extensions, modify them to use the new clean URLs.

βœ… Check Dynamic Links – If your site dynamically generates links (e.g., via a CMS or PHP scripts), ensure they point to URLs without file extensions.

By updating all internal links, you ensure a smooth browsing experience and avoid broken links.

  • Change this:
<a href="about.html">About</a>
  • To this:
<a href="about">About</a>

πŸ”Ή Step 6: Clear Cache and Test

  • Clear your browser cache.
  • Restart Apache (if needed):
systemctl restart apache2  # Ubuntu/Debian
systemctl restart httpd    # CentOS/RHEL
  • Test your new URLs!

βœ… Conclusion

By following these steps, you have successfully removed .html and .php file extensions from your URLs, making them cleaner and more user-friendly. This small yet impactful change enhances your website’s SEO, improves user experience, and makes your links easier to read and remember.

Clean URLs contribute to a more professional web presence, and search engines tend to favor shorter, keyword-rich URLs. Now, your website looks more modern, structured, and optimized for both visitors and search engines. πŸš€

If you have any questions or need further assistance, let us know in the comments or feel free to reach out to Aveshost Support!

Happy optimizing! 😊 

Suggested Reading:

Frequently Asked Questions (FAQs)

Why should I remove .html and .php extensions from my URLs?

Removing file extensions creates cleaner, shorter, and more readable URLs that improve user experience, look more professional, and are preferred by search engines for better SEO rankings.

What do I need before removing file extensions from URLs?

You need an Apache web server with mod_rewrite enabled and access to your website’s root directory to create or edit the .htaccess file.

How do I remove both .html and .php extensions at once?

Add specific rewrite rules to your .htaccess file that redirect both .html and .php URLs to clean versions, then update all internal links throughout your website to remove the extensions.

What should I do after removing file extensions from URLs?

Update all internal links (HTML, PHP, navigation menus, and dynamic links), clear your browser cache, restart Apache if needed, and thoroughly test your new URLs to ensure they work properly.

James Wilson

About Author

For over 10 years, James Wilson has been working in the tech industry. He's an expert in areas like software development, cybersecurity, and cloud computing. He understands the challenges and opportunities that new tech companies face, and he's known for coming up with creative solutions to help them succeed.