how to redirect www.sub.domain.com to sub.domain.com?

After a recent move to a new host I have decided to make my site, a subdomain, stop using 'www'. This greatly helps Boost module save cache space because it doesnt have to cache a www version of the same site.

Some images on my site whose urls are 'www.sub.domain.com/../files/image.jpg' are not appearing now, although they are present at the files dir, just with the wrong image url. Will the solution to the redirect also allow these to appear?

tia!!

Comments

chandan chaudhary’s picture

# To redirect all users to access the site WITHOUT the
'www.' prefix, # (http://www.example.com/... will be redirected to http://example.com/...)

Write the following code in .htaccess file
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

Need Drupal help?
Reach me

Acquia Certified Developer

Backend Frontend and DevOps.

ghmercado’s picture

hi yes i saw this at .htaccess earlier but it doesn't apply as I am using a subdomain.

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

and it didn't work. any ideas please?
thanks.

chandan chaudhary’s picture

its means the your server admin has not given you a permission to override the apache settings. Ask the server admin to give the permission and the try the above code.

Need Drupal help?
Reach me

Acquia Certified Developer

Backend Frontend and DevOps.

alasiri12’s picture

its means the your server admin has not given you a permission to override the apache settings. Ask the server admin to give the permission and the try the above code.

good

Road Runner’s picture

Use the redirect from CPanel. Check out the options there as I recall you can redirect your subdomains and use www or not.

ghmercado’s picture

i dont have cpanel on my vps.