PDA

View Full Version : .htaccess for a subdomain


gennsearch
01-02-2007, 10:21 PM
I redirected my subdomain to my domain.com works good

subdomain.domain.com to www.domain.com works great but the
non www\ subdomain.domain.com does not redirect to www.domain.com

what do I need to add to my .htaccess file to redirect the non www subdomin to www.domain.com


thanks in advanced

robert

evilgreenmonkey
01-03-2007, 04:35 AM
Hi Robert,

Can you post (or PM me) your current mod_rewrite line for the subdomain redirect please?

If you simply want every domain and subdomain pointed at the site to 301 redirect to the main domain, you can use the following code:RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L]

:cool:

Rob

gennsearch
01-03-2007, 10:47 AM
this is what I have now

////////////////////////////////////////////////////////////////////////
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.my-subdomain\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
////////////////////////////////////////////////////////////////////////

it redirects the non www subdomain to www.domain.com
but the www.subdomain.domain.com does not work


thanks for your help

evilgreenmonkey
01-03-2007, 11:46 AM
RewriteEngine on <- turns mod_rewrite on
RewriteCond %{HTTP_HOST} . <- not really needed
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC] <- if domain does not equal www.domain.com
RewriteCond %{HTTP_HOST} !^www\.my-subdomain\.domain\.com [NC] <- or doesn't equal www.my-subdomain.domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L] <- 301 redirect to http://www.domain.com and stick the file path and query on the endThe www. of your subdomain is not redirecting as the 3rd line above is telling it not to.

You can replace your current .htaccess with this:Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L]You should also double check with your web host that there is a DNS record which points www.my-subdomain.domain.com to the correct IP address. If no DNS record (or wildcard) exists for that hostname, the website will not load.

:cool:

Rob

gennsearch
01-03-2007, 12:29 PM
I took the third line out but if I type

www.subdomain.domain.com does not redirect this does

subdomain.domain.com > www.domain.com

evilgreenmonkey
01-03-2007, 12:30 PM
If you PM me (http://forums.searchenginewatch.com/private.php?do=newpm&u=8278) the actual domain and subdomain, I'll take a look for you.

:)

Rob

evilgreenmonkey
01-03-2007, 01:17 PM
I checked the subdomain in your PM and it does look like the following should fix it:Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L]Let me know when you've implemented it and I can check it for you.

gennsearch
01-03-2007, 02:50 PM
I checked the subdomain in your PM and it does look like the following should fix it:Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L]

Let me know when you've implemented it and I can check it for you.

this only redirects the domain.com and not the subdomain.domain.com


Robert

evilgreenmonkey
01-03-2007, 03:44 PM
this only redirects the domain.com and not the subdomain.domain.com
It sounds like your web host has a bodged up way of parking domains. They must be using separate Virtual Host entries for each parked subdomain, rather then a simple Server Alias. I'll research into this and get back to you.