Dev Apache Re-Write for www domain

So many times we need to make copies of our site to dev, but having to manipulate the code/hostname/vhost etc every damn time or setting up .hosts files to point to the dev IP is a pain to say the least.

So here’s my solution for apache2, make all www. addresses convert to dev. addresses, now I can browse my production and dev sites at the same time without 2 machines.

LoadModule substitute_module modules/mod_substitute.so
LoadModule filter_module modules/mod_filter.so
FilterDeclare DEV
FilterProvider DEV SUBSTITUTE resp=Content-Type $text/

 

<VirtualHost *:80>
ServerName dev.jacobdevans.com
ProxyRequests Off
ProxyPreserveHost Off
ProxyPass / http://10.1.4.10/
ProxyPassReverse / http://10.1.4.10/
RequestHeader set Host “www.jacobdevans.com”
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

<Location />
ProxyPassReverse /
RequestHeader unset Accept-Encoding
FilterChain DEV
Substitute “s|www.jacobdevans.com|dev.jacobdevans.com|inq”
</Location>
</VirtualHost>

That is all.

I upgraded my script for HTTP/2 compatibility to use FilterChain, here’s the old command.

# AddOutputFilterByType SUBSTITUTE text/html
# Substitute “s|www.jacobdevans.com|dev.jacobdevans.com|inq”

Say Something Nice