Make URL rewrite skip subdomain

Hi

I needed a non-www to www redirect script that did not add a trailing slash. The scripts you generally find around on the internet add a trailing slash but my CMS has problems with this.

Then I found this nice little script that does not even require a domain name:

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

Problem is, it tried to redirect my subdomain urls to www, wich of course broke the site.
Does anyone understand this language enough to make this script skip subdomain urls (like test.example.com )

Thanks in advance!

If more people ask for this piece of code you migth want to add it to the Search Engine Optimization FAQ thread. (thats where I got my old code)

Aha. A sticky in serious need of updating.

peach,

ARGH! Using scripts that you have no idea what they do! :nono:

The EXACT code you need (explained, of course) is in my signature’s tutorial. Did you bother to look there?

Regards,

DK

I just tried did, even reset apache, and it redirected demo.example.com to www.example.com. This is not what I want…
demo.example.com - leave alone
example.com - redirect to www.example.com
www.example.com - leave alone
Is that possible?

peach,

YES.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\\.com$ [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]

Regards,

DK

It’s finally working properly, thx for sharing your expertise!
If more people ask for this piece of code you migth want to add it to the Search Engine Optimization FAQ thread. (thats where I got my old code)