Using $ GET after a rewrite.?

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
dave_c00
Forum Commoner
Posts: 37
Joined: Wed May 28, 2003 6:08 am

Using $ GET after a rewrite.?

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Use the mod_rewrite QSA flag to enable query strings in rewritten urls:
RewriteRule product-(.*)\.html$ /product.php?id=$1 [L,QSA]
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Post Reply