how to remove php extension from url without htaccess?

how to remove php extension from url without htaccess : Change the .html to .php. Remove .php extension from URL. Before proceeding further, you need to enable mod_rewrite in Apache web server.

php remove extension from url

put this piece of code in the root file .htaccess

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

.htaccess file

RewriteEngine on
#remove extension html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

#remove extension php
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

rewrite .php to no extension

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

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

Removing .php Extension from URL

Read Also:  wordpress ajax call php function - How to send AJAX request in Wordpress?

For example, You required to change URL from http://pakainfo.com/version_1.php to http://pakainfo.com/version_1. Edit .htaccess file and add following settings.

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

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

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

don’t Miss : remove .php from url htaccess

Removing .html Extension from URL

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

Now, If member accessed /version_1 in the browser, it will display the content from /version_1.html. Now, You may required to redirect members which typed complete URL as http://pakainfo.com/version_1.html to the new URL http://pakainfo.com/version_1

Read Also:  Encrypt and Decrypt files using PHP

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

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

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