[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Optional Additional Get Variables

Posted on 2007-03-20
2
Medium Priority
?
716 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
smidgie82 earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

649 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