Skip to content Skip to sidebar Skip to footer

Hide Php File Extension From The Url

I am storing my website's content in a database. It is like a CMS. One will add page content from an admin panel, and content will stored in the database. In one page, I have added

Solution 1:

You can do this in the following way:

Either put this code in your htaccess file (which you don't want), or put this code in your server's configuration file:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^(.*)$ $1.php
</IfModule>

This will hide .php from all URLs of your website.

That's it.

Solution 2:

You need to use URI rewriting, depending on your webserver. For Apache, you can specify it in a .htaccess file, but for nginx, you need to edit the server block of the domain to allow that.

Basically, you need to tell it to rewrite any request like www.example.com/page/abc to www.example.com/page.php/abc (internally, not displayed in the URI bar).

Solution 3:

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

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

Post a Comment for "Hide Php File Extension From The Url"