{"id":4321,"date":"2025-03-27T05:58:48","date_gmt":"2025-03-27T05:58:48","guid":{"rendered":"https:\/\/scriptfeeds.com\/blog\/?p=4321"},"modified":"2025-04-12T19:21:33","modified_gmt":"2025-04-12T19:21:33","slug":"remove-php-or-html-from-url","status":"publish","type":"post","link":"https:\/\/scriptfeeds.com\/blog\/development\/remove-php-or-html-from-url\/","title":{"rendered":"2 Easy steps to remove .php or .html from url of a website"},"content":{"rendered":"\n<p>To remove&nbsp;.php or .html&nbsp;extension from your URLs in a Core PHP website, you&#8217;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&#8217;s mod_rewrite module.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#steps-to-remove-php-or-html-extension-from-website-url\">Steps to remove .php or .html extension from website URL<\/a><\/li><li><a href=\"#code-of-htaccess-file\">Code of .htaccess file<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>We going to do this by taking an example in <a href=\"https:\/\/cpanel.net\/\" target=\"_blank\" rel=\"noopener\">cpanel<\/a>. Below are the steps.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading has-medium-font-size\" id=\"steps-to-remove-php-or-html-extension-from-website-url\"><strong>Steps to remove .php or .html extension from website URL<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a .htaccess file in root directory of your website.<\/li>\n\n\n\n<li>Open the&nbsp;.htaccess file and add the below code( changes domain as per your requirement)<\/li>\n\n\n\n<li>Save the file and now check the URLs by removing .php or .html extensions<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading has-medium-font-size\" id=\"code-of-htaccess-file\"><strong>Code of .htaccess file<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#remove php file extension-e.g. https:\/\/example.com\/file.php will become https:\/\/example.com\/file\nRewriteEngine on \nRewriteCond %{SERVER_PORT} 80 \nRewriteRule ^(.*)$ https:\/\/domainname.com\/$1 &#91;R,L]\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteCond %{REQUEST_FILENAME}\\.html -f\nRewriteRule ^(.*)$ $1.html &#91;NC,L]\nRewriteCond %{REQUEST_FILENAME}\\.php -f\nRewriteRule ^(.*)$ $1.php &#91;NC,L]\n#for forward slash\n&lt;IfModule mod_deflate.c&gt;\n# Compress HTML, CSS, JavaScript, Text, XML and fonts\nAddOutputFilterByType DEFLATE application\/javascript\nAddOutputFilterByType DEFLATE application\/rss+xml\nAddOutputFilterByType DEFLATE application\/vnd.ms-fontobject\nAddOutputFilterByType DEFLATE application\/x-font\nAddOutputFilterByType DEFLATE application\/x-font-opentype\nAddOutputFilterByType DEFLATE application\/x-font-otf\nAddOutputFilterByType DEFLATE application\/x-font-truetype\nAddOutputFilterByType DEFLATE application\/x-font-ttf\nAddOutputFilterByType DEFLATE application\/x-javascript\nAddOutputFilterByType DEFLATE application\/xhtml+xml\nAddOutputFilterByType DEFLATE application\/xml\nAddOutputFilterByType DEFLATE font\/opentype\nAddOutputFilterByType DEFLATE font\/otf\nAddOutputFilterByType DEFLATE font\/ttf\nAddOutputFilterByType DEFLATE image\/svg+xml\nAddOutputFilterByType DEFLATE image\/x-icon\nAddOutputFilterByType DEFLATE text\/css\nAddOutputFilterByType DEFLATE text\/html\nAddOutputFilterByType DEFLATE text\/javascript\nAddOutputFilterByType DEFLATE text\/plain\nAddOutputFilterByType DEFLATE text\/xml\n \n# Remove browser bugs (only needed for really old browsers)\nBrowserMatch ^Mozilla\/4 gzip-only-text\/html\nBrowserMatch ^Mozilla\/4\\.0&#91;678] no-gzip\nBrowserMatch \\bMSIE !no-gzip !gzip-only-text\/html\nHeader append Vary User-Agent\n&lt;\/IfModule&gt;\n&lt;IfModule mod_expires.c&gt;\n  ExpiresActive On\n\n  # Images\n  ExpiresByType image\/jpeg \"access plus 1 year\"\n  ExpiresByType image\/gif \"access plus 1 year\"\n  ExpiresByType image\/png \"access plus 1 year\"\n  ExpiresByType image\/webp \"access plus 1 year\"\n  ExpiresByType image\/svg+xml \"access plus 1 year\"\n  ExpiresByType image\/x-icon \"access plus 1 year\"\n\n  # Video\n  ExpiresByType video\/mp4 \"access plus 1 year\"\n  ExpiresByType video\/mpeg \"access plus 1 year\"\n\n  # CSS, JavaScript\n  ExpiresByType text\/css \"access plus 1 month\"\n  ExpiresByType text\/javascript \"access plus 1 month\"\n  ExpiresByType application\/javascript \"access plus 1 month\"\n\n  # Others\n  ExpiresByType application\/pdf \"access plus 1 month\"\n  ExpiresByType application\/x-shockwave-flash \"access plus 1 month\"\n&lt;\/IfModule&gt;\nErrorDocument 404 \/index.php<\/code><\/pre>\n\n\n\n<p>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<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1015\" height=\"250\" src=\"https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image.png\" alt=\"removal of .php or .html extension\" class=\"wp-image-4630\" srcset=\"https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image.png 1015w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image-300x74.png 300w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image-150x37.png 150w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image-768x189.png 768w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image-399x98.png 399w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image-800x197.png 800w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2025\/03\/image-750x185.png 750w\" sizes=\"(max-width: 1015px) 100vw, 1015px\" \/><\/figure>\n\n\n\n<p>That&#8217;s all, you have to do. For anything else <strong><a href=\"https:\/\/scriptfeeds.com\/blog\/hire-us\/\">connect our Dev here<\/a><\/strong>.<\/p>\n\n\n\n<p>HAPPY CODING<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To remove&nbsp;.php or .html&nbsp;extension from your URLs in a Core PHP website, you&#8217;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&#8217;s mod_rewrite module. We going to do this by taking an example in cpanel. Below [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4304,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jnews-multi-image_gallery":[],"jnews_single_post":{"format":"standard"},"jnews_primary_category":[],"footnotes":""},"categories":[71],"tags":[429,428],"class_list":["post-4321","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-remove-html-from-website","tag-remove-php-from-website"],"_links":{"self":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts\/4321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/comments?post=4321"}],"version-history":[{"count":0,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts\/4321\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/media\/4304"}],"wp:attachment":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/media?parent=4321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/categories?post=4321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/tags?post=4321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}