?
Solved

Optional Additional Get Variables

Posted on 2007-03-20
2
Medium Priority
?
715 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

777 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