skip to Main Content

I see a lot of questions about it here on SO, so I’m posting here:

I have a domain www.example.com and I have set .htaccess file to redirect all example.com to www.example.com

Now, I made (through my plesk 10 interface) a subdomain abc.example.com and what I would like is to also have www.abc.example.com so I entered (also in plesk) this:

www.abc.example.com.    CNAME   abc.example.com.

But it’s not working. Do I need to reload/restart dns?(if so, please tell me how?) Or do I just need to wait certain time for this until it propagates?

Since my mentioned CNAME didn’t work, I also added the .htaccess (which might be wrong (i know, not much of a server person 🙁 )) in the abc folder which looks like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^abc.example.com$
RewriteRule ^(.*)$ http://abc.example.com/$1 [R=301]

but with no luck, so please shed some light.

2

Answers


  1. Chosen as BEST ANSWER

    The solution which worked for me in the end:

    In Plesk I made one subdomain.domain.com pointing to lets say abc folder, and then I added the www.subdomain.domain.com also through Plesk but pointed it to the same abc folder. Then I added the .htaccess file inside this abc folder (where all other files for this subdomain reside) which now guarantees that all requests to subdomain.domain.com get redirected to www.subdomain.domain.com. Here is my .htaccess file:

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

    Hope this will help someone beginning with this stuff like me.

    Just to note, the credit for the idea of pointingthe www.subdomain inside the same folder goes to user Bryan White on serverfault


  2. .htaccess should be like this:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^abc.example.com$ [NC]
    RewriteCond %{SERVER_PORT} =80
    RewriteRule ^(.*)$ http://abc.example.com/$1 [R=301,L]
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^abc.example.com$ [NC]
    RewriteCond %{SERVER_PORT} =443
    RewriteRule ^(.*)$ https://abc.example.com/$1 [R=301,L]
    

    However DNS entry for abc.example.com and www.abc.example.com might not have been propagated. You need to give it sometime (few hours may be) before you test this.

    You can use nslookup on Windows or *nix to check when is your domain is available to the world.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search