Link to home
Start Free TrialLog in
Avatar of marcparillo
marcparillo

asked on

htaccess chaining rules with variables

Hello experts,

I have a series of .htaccess rules that are working well on my Unix server.  I just need to add one extra rule to the chain and I don't know how to do it.  

Currently, for every request that comes in, I strip off the last part of the URL and attach it to a PHP page. Like this:

RewriteRule ^(db)\/(\w*)\/?(\d)?$ index.php?page=$1&dbid=$2&autoplay=$3
RewriteRule ^(db_search)\/(.*)$ index.php?page=$1&search=$2

I also need to add a rule that makes sure there is a www prefix, after all of the other rules have been exercised -- like this:

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L]

I don't understand how to use the [E] or [ENV] flag to attach those variables ($1,$2,$3) to the last RewriteCond, so that if the entire request came in as http://mydomain/db/abc/123 or mydomain.com/db/abc/123, the URL would ultimately be http://www.mydomain/db/abc/123.

Thank you
-marc
SOLUTION
Avatar of oldmanbim
oldmanbim
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of arober11
arober11
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial