Solved

Optional Additional Get Variables

Posted on 2007-03-20
2
675 Views
Last Modified: 2012-05-05
I have this in my htaccess, which works fine:
RewriteRule ^product/(.*)/(.*)/(.*).php$ /naughty/products/product.php?DPID=$2

I would like to be able to pass 'additional' optional get variables. so I was thinking something like (this does not work though):
RewriteRule ^product/(.*)/(.*)/(.*).php\??(.*)$ /naughty/products/product.php?DPID=$2&$4
0
Comment
Question by:sypder
2 Comments
 
LVL 9

Accepted Solution

by:
smidgie82 earned 500 total points
ID: 18760132
The problem is that the RewriteRule directive only matches its regex against the URL, not the query string.  So, when you visit, for instance, http://example.com/product/1/2/3.php?color=gray, your RewriteRule only sees "/product/1/2/3.php".

If you want "color=gray" to be appended, as your rule indicates, you should do the following instead:
RewriteRule ^product/(.*)/(.*)/(.*).php\??(.*)$ /naughty/products/product.php?DPID=$2&%{QUERY_STRING}

Of course, if there was no query string initially, the new URL will look like "/naughty/products/product.php?DPID=2&", which probably is not what you want.  So instead, you can use the QSA flag, and any part of your new URL that Apache recognizes as part of a query string (i.e., anything after '?') will be _appended_ to the existing query string, instead of replacing it:
RewriteRule ^product/(.*)/(.*)/(.*).php\??(.*)$ /naughty/products/product.php?DPID=$2 [QSA]

I haven't tested the above for syntactic correctness, but the reasoning is correct.  I hope that helps!
0
 
LVL 3

Author Comment

by:sypder
ID: 18761755
Perfect!

Just for archival purposes. the final syntax I used was:

RewriteRule ^product/(.*)/(.*)/(.*).php$ /naughty/products/product.php?DPID=$2 [QSA]
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now