You are not logged in.

#1 2010-09-19 08:03:24

Lazar
Member
Registered: 2010-09-01
Posts: 14

[solved] apache: rewriting www.domain* as domain* in httpd.conf

After Googling and checking the apache manual, it seems to me that the following should do the trick:

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

I have this in my /etc/httpd/conf/httpd.conf (and it also contains "LoadModule rewrite_module modules/mod_rewrite.so"). I don't have the above enclosed between any tags because I want to apply to all urls I serve from that machine.

...but it doesn't work. The setting seems to be ignored as the "www." part doesn't disappear in my browser when visiting www.mydomain.com

Anyone have an idea what I'm missing?

Last edited by Lazar (2010-09-19 10:17:45)

Offline

#2 2010-09-19 10:16:53

Lazar
Member
Registered: 2010-09-01
Posts: 14

Re: [solved] apache: rewriting www.domain* as domain* in httpd.conf

Nevermind. I failed to put "RewriteEngine On" in httpd.conf. It works now.

I had misinterpreted the apache documentation and thought that directive only applies within directory and virtual host sections (plus, I did try it once, but at that time I apparently had made another mistake which prevented me from seeing the result) tongue

Offline

#3 2010-09-19 11:51:23

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [solved] apache: rewriting www.domain* as domain* in httpd.conf

This other way to do it is to match anything EXCEPT the host you want to use, then you know it will always be rewritten to what you want:

RewriteCond %{HTTP_HOST} !^www.example.com [nocase]
RewriteRule ^/(.*)$ http://www.example.com/$1 [redirect=permanent,last]

Offline

Board footer

Powered by FluxBB