简体   繁体   中英

Is it better to 301 redirect requests to a www. subdomain or non-www?

A lot of people talk about 301 redirecting incoming requests to one canonical url for SEO or other purposes.

This can be useful. Suppose if for example a search engine ranked the urls and unfortunately treated a url with a www. and without differently. Like for example, for Facebook, there is http://facebook.com , http://www.facebook.com , (and even more, like https://).

I guess my question would be, if there is a difference, would it be better overall to redirect to the url with a www. subdomain, or without? Reasoning would be really appreciated. Thank you.

Often, shorter is better (eg use domain.com instead of www.domain.com), since your URLs will be shorter and thus your HTTP requests and responses will also be smaller.

However, one thing to keep in mind is that if your site uses cookies, and you set a cookie on domain.com, that will get sent to all subdomains. If you want to keep a "cookieless" subdomain for performance reasons (eg requests for images at images.domain.com don't carry the cookies) then you should consider using the "www." prefix in the canonical URLs if you need cookies to be sent in the requests for pages but not for sub-resources.

You'll also want to use the "www." form if your domain is of a funky (ccTLD) format like XX.YY, because cookies work properly on www.XX.YY but you'll have problems with older browsers if you try to set cookies on XX.YY.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM