1

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 "www.lorem.com".

Doing:

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!

Tom
  • 113
  • 4
  • 1
    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. – jaseeey Jan 15 '14 at 04:01

1 Answers1

0

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
Elliptical view
  • 684
  • 6
  • 9