Creating nice URLs with PHP and Apache, without mod_rewrite
I notice that a lot of people want to know how to create "pretty" URLs, that are more human readable than
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:
1. Create a PHP script which uses PATH_INFO. Path info is the part of the path *after* the PHP script's URL. Example:
This can be got using $_SERVER['PATH_INFO']
2. 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
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:
This is considerably more human-readable than something with a query string in.
Whoa...oddly enough I'm right now trying to write some stuff that deals with uri processing. Another approach to try out here...
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)