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
How to hide the extension of a page from URL
Moderator: General Moderators
Re: How to hide the extension of a page from URL
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 +MultiViewsRe: How to hide the extension of a page from URL
Ya I want to forcibly remove the extension from URL, but not getting that what will be the Code...
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: How to hide the extension of a page from URL
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]
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
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.
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
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.
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]