简体   繁体   English

从无Cookie的域提供静态内容-使用子域和.htaccess

[英]Serving Static Content from a Cookieless Domain - using subdomain and .htaccess

I can have many images per page (eg 70) and want to serve them without the overhead of cookies. 我每页可以有很多图像(例如70张),并且希望在不增加Cookie开销的情况下提供它们。

I would prefer to set up a subdomain and add a CNAME record (as opposed to having to use a separate domain). 我宁愿设置一个子域并添加一个CNAME记录(而不是必须使用单独的域)。 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. 目前,我有一个用于域名的CNAME记录:www.example.com ==> example.com,并且我想保留将example.com解析为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. 我发现,当我使用www.example.com访问我的网站时,它会使用与使用example.com时不同的cookie。 Could I use .htaccess to redirect all example.com requests to www.example.com requests and solve the problem this way? 我可以使用.htaccess将所有example.com请求重定向到www.example.com请求,并以此方式解决问题吗? Would all cookies then default to www.example.com when set? 设置后,所有cookie都会默认为www.example.com吗?

UPDATE Then I would create the CNAME record static.example.com and point it to www.example.com. 更新然后,我将创建CNAME记录static.example.com,并将其指向www.example.com。 I would then point all my image requests to static.example.com. 然后,我会将所有图像请求都指向static.example.com。 Would they be cookieless? 他们会没有饼干吗?

Yes that's what is needed and good for SEO too. 是的,这正是SEO所需要的,也很不错。 Multiple url for same content is not a good thing. 同一内容的多个url不是一件好事。 You need to make changes in htaccess file written below. 您需要对下面编写的htaccess文件进行更改。

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

You're on the right track, but it's not immediately guaranteed that static.example.com will be cookieless. 您的工作方向正确,但不能立即保证static.example.com是无cookie的。 You'll need to explicitly set all your cookies for www.example.com so that they won't be shared among subdomains. 您需要为www.example.com显式设置所有cookie,以便它们不会在子域之间共享。 A separate domain is much easier to deal with in this regard. 在这方面,更容易处理一个单独的域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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