Serving Static Content from a Cookieless Domain -

2019-08-09 04:31发布

I can have many images per page (e.g. 70) and want to serve them without the overhead of cookies.

I would prefer to set up a subdomain and add a CNAME record (as opposed to having to use a separate domain). Currently, I have a CNAME record for my donmain: www.example.com ==> example.com and I want to keep the functionality of resolving example.com to www.example.com.

I've discovered that when I access my site using www.example.com it uses different cookies from when I use example.com. Could I use .htaccess to redirect all example.com requests to www.example.com requests and solve the problem this way? Would all cookies then default to www.example.com when set?

UPDATE Then I would create the CNAME record static.example.com and point it to www.example.com. I would then point all my image requests to static.example.com. Would they be cookieless?

2条回答
beautiful°
2楼-- · 2019-08-09 05:17

Yes that's what is needed and good for SEO too. Multiple url for same content is not a good thing. You need to make changes in htaccess file written below.

RewriteBase / RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

查看更多
别忘想泡老子
3楼-- · 2019-08-09 05:24

You're on the right track, but it's not immediately guaranteed that static.example.com will be cookieless. You'll need to explicitly set all your cookies for www.example.com so that they won't be shared among subdomains. A separate domain is much easier to deal with in this regard.

查看更多
登录 后发表回答