/ dynamic urls

How to Handle Dynamic URLs

I've noticed that a lot of CMSes that try to use a query string and rewrite it in an .htaccess. For example:

http://domain.com/index.php?path=galley/birthday-pics or http://domain.com/index.php?page=galley&item=birthday-pics and translate it into http://domain.com/galley/birthday-pics via .htaccess. Then they just use the $_GET superglobal to access the information they need.

I see a couple problems with this. First, it doesn't degrade very nicely (http://domain.com/index.php?page=galley&item=birthday-pics isn't a super pretty URL), and it prevents you from using your own query string in a normal way. For example, if you tried using http://domain.com/galley/birthday-pics?sidebar=false it would be seen as http://domain.com/index.php?page=galley&item=birthday-pics?sidebar=false, which would mess up accessing the variables in $_GET.

You could just use the URL http://domain.com/galley/birthday-pics&sidebar=false, but that looks even more awkward and can cause confusion with people that know a little about URLs and other developers, etc.

I've seen many other CMSes handle it better, and so I thought I'd investigate to see what I could find. I couldn't find much, but I thought I'd just experiment.

What I found out, is that it seems that when Apache reaches the index.php part of a URL, it seems to ignore everything after that. This provides an interesting opportunity. For example you can use a URL such as http://domain.com/index.php/galley/birthday-pics, and the code still goes through index.php, and you can use REQUEST_URI in $_SERVER (remember to strip out the index.php part in case your client can't use mod_rewrite).

Interestedly enough, it does seem to stop processing the URL as soon as it sees index.php. You could go to domain.com/index.phpabout and it would still process call index.php. But by using this method, it has a relatively prettier fallback (just has an extra index.php in it (which if they have mod_rewrite, isn't an issue)), and you can use query strings like normal.

I am sure this is indeed documented and I just didn't know what to search for, but these were just my findings.