Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
add comment

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:

127.0.0.2       www.mysite.local
127.0.0.3       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.

share|improve this answer
    
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 Jul 13 '10 at 8:57
    
Sounds good, I'll try that out. –  Don Kirkby Jul 14 '10 at 17:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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