I've got developers editing pages for several sites on a WAMP stack and then uploading to the public servers running LAMP stacks. We're pretty happy with it, but we have this minor annoyance: we can't quite use the same .htaccess files in the development and production environments. On the public sites, the source folder maps to http://foo.com, http://bar.com, and so on. On the developer workstation, the source folders map to http://localhost/foo, http://localhost/bar, and so on. That means that I need RewriteBase / for the public servers, while each site on the developer workstation uses RewriteBase /foo/, RewriteBase /bar/, or whatever.

Is there any way to specify the RewriteBase relative to the .htaccess file? Any other ideas for how to make my rewrite rules more portable?

If you're curious, I'm using rewrite rules to redirect to CakePHP routing code, so the rule looks like this:

RewriteRule ^(.*)$ cake_main.php?url=$1 [QSA,L]

If I don't use a RewriteBase of /foo/ on the developer workstation, then it will rewrite to /cake_main.php instead of /foo/cake_main.php.

1 Answer 1


My solution to this hasn't been to mess with the rewrite rules, but to add separate local domains/hosts with fake TLDs to my PC.

You can do this by editing the file C:\Windows\System32\drivers\etc\hosts

Be aware that on Windows 7 (and maybe Vista) that in order to successfully edit this file you need to run your text editor as Administrator.

You can add hosts using lines that look like:       www.mysite.local       www.myothersite.local

Once these are in place, you can configure Apache for these domain names and you'll be good to go.

Of course, this doesn't work to well testing from other machines in the local network, but if you're in that situation it may be better to use a local DNS server or to assign the hosts to local non-portable IP addresses and synchronize the files across all PCs.

  • That's the same thing I do on my Linux desktop. Its much easier to just set up a bunch of virtual hosts than dealing with having to edit files / push / then revert locally.
    – Tim Post
    Commented Jul 13, 2010 at 8:57
  • Sounds good, I'll try that out.
    – Don Kirkby
    Commented Jul 14, 2010 at 17:10
  • "this doesn't work to well testing from other machines" - If you use a subdomain instead of a TLD eg. local.example.com, you can set this as an A record in the DNS, no need to edit the HOSTS file (if you are connected to the internet), and this will work for all machines (including mobile devices) on the local network. This also allows you to keep development/live cookies separate if you wish.
    – MrWhite
    Commented Dec 10, 2015 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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