Page 1 of 1

Using $ GET after a rewrite.?

Posted: Wed Jul 18, 2007 6:55 am
by dave_c00
Hi,
I am using RewriteRule to sort out my urls in htaccess. The problem is that now I need to record a $_GET that is on the end of the url when it comes from a google ad.

example:

/product-1-widget.html (is my normal url which works fine)
/product-1-widget.html?ad=google (is the new url that I want to get $_GET['ad'] from but because I am already rewriting it doesnt work)

I currently use this RewriteRule line:

RewriteRule product-(.*)\.html$ /product.php?id=$1 [L]

Thanks

Dave

Posted: Wed Jul 18, 2007 8:07 am
by Zoxive
did you try adding a new line below it?

Code: Select all

RewriteRule product-(.*)\.html$ /product.php?id=$1 [L]
RewriteRule product-(.*)\.html?ad=(.*)$ /product.php?id=$1&ad=$2 [L]

# (.*) matches anything
# RewriteRule product-([0-9]+)\.html$                   /product.php?id=$1 [L]
# RewriteRule product-([0-9]+)\.html?ad=([a-zA-Z]+)$    /product.php?id=$1&ad=$2 [L]
But isn't the hole point of rewriting urls to make them clean and not have to show the get variables?

Posted: Wed Jul 18, 2007 10:26 am
by vigge89
Use the mod_rewrite QSA flag to enable query strings in rewritten urls:
RewriteRule product-(.*)\.html$ /product.php?id=$1 [L,QSA]

Posted: Wed Jul 18, 2007 4:50 pm
by alex.barylski