Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET variables and pretty urls

Tags:

url

php

get

i think this is a bit of a noob question, but here goes.

I am trying to get a better understanding $_GET variables in PHP. A lot of CMS's etc convert things like site.com/?ID=42 into something like site.com/42

My question is, what happens to the $_GET variables when this happens? I try and print the GET array on page load, and it is empty.

like image 929
mroggle Avatar asked Jan 20 '26 10:01

mroggle


1 Answers

The way they do this is using mod_rewrite

Basically you have the webserver "rewrite" URI requests to something else, so you have incoming requests like

http://your.site.com/Page/arg1/arg2/arg3

But with your REWRITE RULE, you'll have Apache turn requests that match this pattern (all requests bound for /Page) into:

http://your.site.com/Page?a=arg1&b=arg2&c=arg3

You'd then finally in PHP have $_GET[ 'a' ], $_GET[ 'b' ] and $_GET[ 'c' ] all set to values.

Check out this book

like image 58
bobobobo Avatar answered Jan 22 '26 02:01

bobobobo