Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to come up with some redirect rules that'll work on my local working directory and production. The problem being my local dev env works via "localhost/exp" where as the production works from the root of the domain "".


RewriteEngine On
RewriteCond ^rec.php /core/rec [R=301,L]

Works on production no worries, but on my local it redirects to : "localhost/core/rec", where as I want it to to be "localhost/exp/core/rec"

I'd prefer not to have to hardcode "exp" in there, so far I found the only way todo it is have seperate rules per environment, I could make it work on my local using:

RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)/exp/(.*)
RewriteRule ^rec.php /exp/core/rec [R=301,L]

Appreciate any help on this one. Thanks!

share|improve this question

marked as duplicate by Falcon Momot, Iain, mdpc, Dave M, dawud Feb 9 '14 at 18:54

This question was marked as an exact duplicate of an existing question.

You may be able to try and experiment with the "RewriteCond %{HTTP_HOST} ^localhost" parameter in the .htaccess file. I haven't done this before though as I use Nginx, so just a suggestion on where to maybe look. – Jason Ilicic Jan 15 '14 at 4:01
up vote 0 down vote accepted

Prefix your RewriteRule(s) with a RewriteCond matching any of the 'server internals'. See the full list of server internals here.

SERVER_NAME is the one that jumps out at me as possibly the best to use, so for example your it would use this (additional) prefix to your RewriteRule:

RewriteCond %{SERVER_NAME} localhost

or for other than localhost:

RewriteCond %{SERVER_NAME} !localhost
share|improve this answer
I tested this and it works. – Eliptical view Jan 16 '14 at 11:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.