I notice that a lot of people want to know how to create "pretty" URLs, that are more human readable than
http://mysite.example.com/something.php?id=12364
A lot of people use mod_rewrite to achieve this. Although this works, it's a lot of hassle and not always available.
Here's an alternative method I use:
- Create a PHP script which uses PATH_INFO. Path info is the part of the path after the PHP script's URL. Example:
http://mysite.example.com/something.php/123456
This can be got using $_SERVER['PATH_INFO']
- To make things nicer, I use a PHP script whose filename doesn't end in .php. This is pretty straightforward if you're using Apache, because
<Files en>
ForceType application/x-httpd-php
</Files>
in .htaccess causes any file called 'en' to be treated as a PHP script despite its name NOT ending in .php. In fact you could do this for all your PHP scripts. Or you could make a single script which invokes the appropriate function based on its PATH_INFO.
The URLs on our shop sites can look something like this:
http://www.worldofhealth.co.uk/en/keep-fit/keep-fit-accessories/exercise-yoga-mats/studio-mat/studio-pro-mat-standard
This is considerably more human-readable than something with a query string in.
Mark