Page 1 of 1

Parsing GET values

Posted: Mon Mar 02, 2009 6:11 am
by smriyaz
Hi everyone,

I am using htaccess to rewrite the standard index.php + page_number url as directory/filename.

With this in mind, how do I then parse additional _GET values?

For example,
mysite.com/directory/title?additional_info=something
In this example, directory/title is a rewritten _GET value, so how do I get a hold of additional_info?

Thanks for your help and apologies if this is difficult to understand

Re: Parsing GET values

Posted: Sun Mar 08, 2009 11:56 am
by plger
Suppose you have the following redirection set (I know it isn't, but for the sake of the explanation this will do) ::

Code: Select all

RewriteRule ^([^/]+)/?$ index.php?page=$1 [L]
This would rewrite http://www.domain.com/somepage to /index.php?page=somepage
If you had the following url :
http://www.domain.com/somepage?var=value
It would indeed rewrite it without the get parameters.
What you could do, is change the rewrite rule to this:

Code: Select all

RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA]
QSA here means Query String Append : it means that what's after the ? will be added at the end of the rewritten url. So the output would be:
http://www.domain.com/index.php?page=somepage&var=value

Hope this helps,
Pierre-Luc