How to hide .php extension from url with .htaceess?
- Admin
- 2016-08-07 14:56:28
- 1,204
There are many reasons that we want/need to hide extensions from the url. One of the major benefits of hiding extension from url is that if we are going to change hosting from windows to linux or vice versa we can still have same url structure and will not lose seo rankings.
Here is a sample .htaccess code that we will need to do this.
If it's just a simple page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/?$ page.php [L]
This will redirect /page.php to page
If page accepts parameters
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/([^/]+)/([^/]+)/?$ page.php?prm=$1&prm=$2 [L]
With this you can write page.php?prm=value1&prm=value2 as page/value1/value2