[Cialug] HTTP forwarding/proxying-ish something

Matthew Nuzum newz at bearfruit.org
Mon Jul 7 08:56:17 CDT 2008


On Sun, Jul 6, 2008 at 6:43 PM, Zachary Kotlarek <zach at kotlarek.com> wrote:
>>>      leeloo /etc/httpd/vhosts 0$ cat 09-proxy.conf
>>>      <VirtualHost *:80>
>>>              ProxyRequests off
>>>              ServerName proxy.cynicbytrade.com
>>>              ProxyPass / http://www.google.com/
>>>              ProxyPassReverse / http://www.google.com/
>>>      </VirtualHost>

>> Any apache tricks to easily forward foo.com to www.foo.com?
>
> I'd setup a vhost for foo.com and unconditionally redirect:
>

You don't need a vhost, instead just set a ServerAlias directive in
the proxied vhost and then use the conditional redirect Zach listed
here:

>
> You could also match a conditional direct with something like:
>
>        rewriteCond %{HTTP_HOST} !^www\. [NC]
>        RewriteRule     (.*) http://www.foo.com/$1 [L,R]

I use this:

    ServerName www.foo.com
    ServerAlias  foo.com # you can have more aliases if you like
    RewriteCond %{HTTP_HOST}    !^www.foo.com(:80)?$
    RewriteRule ^/(.*)                      http://www.fooo.com/$1 [L,R]

Also you can use 301 redirects instead of 302's by doing:

    RewriteRule (.*) http://www.foo.com/$1 [R=301,L]

It is bad for testing but good once your URLs and domains are fixed.
301 is a permanent redirect, 302 is a temporary one.

Also, if your site is busy or hosts dynamic content you can do the
same things as above with squid and reap great rewards. Squid is far
more intelligent of a proxy than apache is. You just need to move
apache to a different port or interface than the one squid is using.

-- 
Matthew Nuzum
newz2000 on freenode


More information about the Cialug mailing list