Hi
I have a site with around 30 pages. I would like users to be able to type in
www.mysite.com/example
At the moment to get to this page my users would have to type www.mysite.com/example.php
How would I make this feature ?
| SitePoint Sponsor |
Hi
I have a site with around 30 pages. I would like users to be able to type in
www.mysite.com/example
At the moment to get to this page my users would have to type www.mysite.com/example.php
How would I make this feature ?


The easiest thing to do is to let them type mysite.com/example/—that is, with a slash on the end. You do this by creating a folder inside your root folder called /example/ and moving the example.php file to that folder and renaming it as index.php.
An alternative is to rewrite your URLs with a .htaccess rule, but that's a little tricker and messier ... although it means you don't have to restructure your site.
Often sites have a structure like mysite.com/example because their pages are served up by a CMS that creates such URLs by default. But rebuilding your site within a CMS is most likely the most time consuming option.

Any posts I write in Arial are on my mobile phone, so please excuse typos etc.
Any posts I write in Verdana are on a PC, so feel free to berate me mercilessly for any mistakes

If you only ever reference the non-extension format of the URL then that's all that should ever appear. Failing that, you can simply add a canonical link into the <head> giving the preferred URL format.
The problem with using a visible rewrite is that search engines will genuinely use the actual URL rather than the alias URL (in this case, they would normally prefer the URL with extension), whereas if you're trying to promote your site then you are likely to want to prefer the non-extension format.
Any posts I write in Arial are on my mobile phone, so please excuse typos etc.
Any posts I write in Verdana are on a PC, so feel free to berate me mercilessly for any mistakes
Bookmarks