views:

66

answers:

2

I would like to build a php website and I would like to remove all the strings that make the url to seem dynamic. However I still need to get information through GET so basically I don't know how to do that because I need to pass a parameter to $_GET request which obviously would be dynamic . For example I may have www.domain.com/mobile_phones where mobile_phones would be the parameter/information that I should get . Any help would be highly appreciated

+1  A: 

You do this through a process called "routing". Normally you set up rewrite rule to forward everything to a single entry point - index.php then index.php intializes youre application witch makes use of some kind of routing class. This routing class compares the REQUEST_URI to a list of known patterns. When it matches i pattern it takes car of parsing out all the variables form the URI.

On the other end of things, to generate the proper urls wihtin the app there are usually a number of helpers that take a series of parameters along with a controller/action and generate a URL based on the same routing rules.

Take a look at the Zend_Controller package from Zend framework for a good example.

prodigitalson
+1  A: 

URL rewriting works by translating the received URL string into a more suitable format, including get parameters. For example

RewriteEngine On
RewriteRule ^([0-9])/.*$ index.php?id=$1

This will translate a string that's says, say example.com/1234/my-page to example.com/index.php?id=1234 and id will be accessible directly from the $_GET array.

Zurahn
prodigitalson