Solved

htaccess chaining rules with variables

Posted on 2010-08-30
2
474 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:marcparillo
[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 4

Assisted Solution

by:oldmanbim
oldmanbim earned 250 total points
ID: 33575214
0
 
LVL 26

Accepted Solution

by:
arober11 earned 250 total points
ID: 33577485
Hi, loose the [L]  (Last) from the HTTP_HOST rewrite, and make it the first rule. Any URL modified by that URL will then just drop into your other rules, before possibly being returned to the users browser e.g.

RewriteCond %{HTTP_HOST} !^www.mydomain\.com$ [NC]
RewriteRule .* http://www.mydomain.com%{REQUEST_URI}
RewriteRule ^(db)\/(\w*)\/?(\d)?$ index.php?page=$1&dbid=$2&autoplay=$3
RewriteRule ^(db_search)\/(.*)$ index.php?page=$1&search=$2


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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