Scriptfeeds Blog
  • Blog
  • WordPress
    • Woocommerce
    • WordPress Errors
    • WordPress Plugins
  • Development
    • WordPress Themes
  • Hire us
Cart / $0.00

No products in the cart.

No Result
View All Result
Scriptfeeds Blog
  • Blog
  • WordPress
    • Woocommerce
    • WordPress Errors
    • WordPress Plugins
  • Development
    • WordPress Themes
  • Hire us
Cart / $0.00

No products in the cart.

No Result
View All Result
Scriptfeeds Blog
No Result
View All Result
Home Development

2 Easy steps to remove .php or .html from url of a website

Scriptfeeds by Scriptfeeds
March 27, 2025
in Development
0
84
SHARES
Share on FacebookShare on TwitterWhatsapp this Blog

To remove .php or .html extension from your URLs in a Core PHP website, you’ll need to use a .htaccess file in server root folder. By removing .php or .html from url, makes its user friendly. This functionality can be achieved using Apache’s mod_rewrite module.

Table of Contents

  • Steps to remove .php or .html extension from website URL
  • Code of .htaccess file

We going to do this by taking an example in cpanel. Below are the steps.

Steps to remove .php or .html extension from website URL

  1. Create a .htaccess file in root directory of your website.
  2. Open the .htaccess file and add the below code( changes domain as per your requirement)
  3. Save the file and now check the URLs by removing .php or .html extensions

Code of .htaccess file

#remove php file extension-e.g. https://example.com/file.php will become https://example.com/file
RewriteEngine on 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://domainname.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
#for forward slash
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
 
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
<IfModule mod_expires.c>
  ExpiresActive On

  # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Video
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
ErrorDocument 404 /index.php

Above code also adds Zip compression in files. Once done, clear the cache and History and browser and access pages with .php or .html extension

removal of .php or .html extension

That’s all, you have to do. For anything else connect our Dev here.

HAPPY CODING

Connect with Developer
Loading
Tags: Remove .html from websiteRemove .php from website
Share34Tweet21Send

Leave a Reply Cancel reply

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

I agree to the Terms & Conditions and Privacy Policy.

Scriptfeeds Blog

© 2022 Scriptfeeds

Blog Categories

  • WordPress
  • Development
  • Reviews
  • Marketing

Connect us on

No Result
View All Result
  • Blog
  • WordPress
    • Woocommerce
    • WordPress Errors
    • WordPress Plugins
  • Development
    • WordPress Themes
  • Hire us

© 2022 Scriptfeeds

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.