how to remove php extension from url in localhost?

In this post we will show you remove .php from url htaccess, hear for how to change url using htaccess in php we will give you demo and example for implement.

Throughout, In this tutorial you’ll learn remove php extension from url cpanel.This article goes in detailed on implementing how to remove html extension from url without htaccess.If you want to learn how to remove php extension from url using javascript. So, from this post, you can find step by step process of doing remove php from url htaccess aws.

How to Remove File Extension (.php, .html) from URL using .htaccess

There are the Following The simple About remove php from url localhost Full Information With Example and source code.

As I will cover this Post with live Working example to develop Remove File Extention from URLs

Removing .php Extension from URL
change URL from http://4cgandhi.com/example.php to http://4cgandhi.com/example. Edit .htaccess file and add following settings.

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

Now, If user accessed /example in the browser, it will show the content from /example.php. But still, if any user typed completed URL as http://4cgandhi.com/example.php, this will not redirect. Now you need to add some more rules to the .htaccess file.

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]

Removing .html Extension from URL

For example you need to convert your url from http://4cgandhi.com/example.html to http://4cgandhi.com/example. Edit .htaccess file and add following settings:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]

Now, If user accessed /example in the browser, it will show the content from /example.html. Now, You may need to redirect users which typed complete URL as http://4cgandhi.com/example.html to the new URL http://4cgandhi.com/example

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
Web Programming Tutorials Example with Demo

I hope you get an idea about how to remove .php from url?.
I would like to have feedback on my pakainfo.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment