View Full Version : Using "/" instead of "?" for php values in URL

08-11-2007, 09:38 AM
Hey everyone!

You all know the $_GET statement, getting the values after "?var=1&type=2"...

Is there a way of saying "http://www.mysite.com/1/2" and getting PHP to read the variables from this, at the same time keeping the browser in the root directory?

I reckon this would help google index my site as well.

Thanks a lot!! :thumbsup:

08-11-2007, 09:49 AM
Are you wanting to know how to have your URL rewritten from your 1st example to look like in your 2nd example?

If you're server is Apache. I think you should look into Mod Rewrite :). www.modrewrite.com

08-14-2007, 07:54 AM
I do this quite frequently. I think I borrowed the same approach drupal uses, which is to grab everything, call it some variable, and rewrite to a script that parses the url.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} (\.php$|\/$)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Then index.php splits up $q and knows what to do. This gives you lots of control.