Mobile app version of vmapp.org
Login or Join
Si4351233

: Apache rewrite rules for development workstation and server 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

@Si4351233

Posted in: #Apache #Htaccess #ModRewrite #UrlRewriting

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 foo.com, bar.com, and so on. On the developer workstation, the source folders map to localhost/foo, 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= [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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Si4351233

1 Comments

Sorted by latest first Latest Oldest Best

 

@RJPawlick198

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:WindowsSystem32driversetchosts

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme