Page 1 of 1
How to hide the extension of a page from URL
Posted: Wed Nov 10, 2010 11:13 pm
by dheeraja
Hi Guys,
I want to hide the page extension from URL but not getting how to do this stuff, suppose i m having a url "
www.example.com/contact.php" then I just want that browser should show "
www.example.com/contact".
Thank you
Dheeraj
Re: How to hide the extension of a page from URL
Posted: Thu Nov 11, 2010 12:12 am
by requinix
If you have Apache you can use the MultiViews option and it'll add the extension behind the scenes for you; URLs both with and without extension will work. If you want to forcibly remove the extension from the URL then you'll need URL rewriting as well.
Code: Select all
# in your .htaccess file
Options +MultiViews
Re: How to hide the extension of a page from URL
Posted: Thu Nov 11, 2010 12:19 am
by dheeraja
Ya I want to forcibly remove the extension from URL, but not getting that what will be the Code...
Re: How to hide the extension of a page from URL
Posted: Thu Nov 11, 2010 5:17 am
by klevis miho
You should do a URL rewrite in apache, and change the way the link is called.
For example in you code now it is: <a href="/contact.php">Contact</a>
You should change it to: <a href="/contact">Contact</a>
And it the htaccess put this line:
RewriteEngine on
RewriteRule ^contact$ /contact.php [R=301,L]
Re: How to hide the extension of a page from URL
Posted: Thu Nov 11, 2010 6:02 am
by dheeraja
so should I have to write all pages name like
RewriteRule ^contact$ /contact.php [R=301,L]
RewriteRule ^abc$ /abc.php [R=301,L]
RewriteRule ^xyz$ /xyz.php [R=301,L]
and like wise.
Re: How to hide the extension of a page from URL
Posted: Thu Nov 11, 2010 11:29 am
by requinix
Or you could do what I mentioned and use MultiViews instead.
To forcibly remove the extension,
1. Fix the various links and stuff that you have pointing to whatever.php.
2.
Code: Select all
RewriteEngine on
RewriteRule (.*)\.php$ $1 [R]