Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule: remove www from all urls

remove www rewriterule

         

xname

10:10 am on Mar 1, 2007 (gmt 0)

10+ Year Member



Hello,
on my server I'm trying to remove all 'www' string from all subdomains
For example:
[sub1.domain.com...] -> [sub1.domain.com...]
[sub2.domain.com...] -> [sub2.domain.com...]
...
Can you help me to understand what's the right rewrite rule to use?

I suppose I've to put this rule in httpd.conf and apply it at Server level.
I'm using this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.

What rewrite rule should I use?
Thanks

jdMorgan

2:27 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I understand your question, something like:

RewriteEngine on
#
# If "www" prefix on subdomain, get the subdomain into %1 and then...
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com
# redirect to requested page in same subdomain, but without "www" prefix
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]

Jim

xname

7:38 pm on Mar 1, 2007 (gmt 0)

10+ Year Member



Thanks.

Excuse me where have I to write this lines in httpd.conf?

I've added them above virtual server sections, restarted apache but nothing seems to happen.