Apache2: mod_rewrite vs. mod_proxy

I can’t quite figure this out. I’m trying to write a simple rule to force randys.org to redirect to www.randys.org but it’s not realy working. Of course, I haven’t tried it on a vhost that isn’t proxying request to mongrel. Here’s the rule:

RewriteEngine On
RewriteCond %{HTTP_HOST}    !^www.randys.org$ [NC]
RewriteCond %{HTTP_HOST}    !^$
RewriteRule ^/(.*)          http://www.randys.org/$1 [R=301,L]

Anyone?

2 Comments

  • John Gruber did a write-up about this topic last year. You might find the information helpful.

    I haven’t tested it, but I think this is what you want:

    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^randys.org$
    RewriteRule (.*) http://www.randys.org/$1 [R=Permanent]
    

    Nice redesign, by the way…

  • Hmmm, for some reason, this isn’t working. I’ve added this to the main apache2 config as well as the config for the site and the .htaccess file. I seems like it just ignore it. I’m wondering if it has something to do with mod_proxy?

    Thanks… some random template. ;)