0

UPDATE: Removing the rule below solves the unnecessary redirection. Now it just works fine. Though it is still reachable from two places, a canonical header solves the duplicate issue i guess.

I configured my site to have a static sub-domain like static.example.com. In this sub-domain's nginx config i have this:

if ($request_uri !~* "\.(jpe?g|gif|css|png|js|ico....)$") {
    rewrite ^(.*) https://www.example.com$1 permanent;
    break;
}

From W3 Total Cache panel i activated CDN to "Generic Mirror" and put the static.example.com as my CDN.

Now the images and css-js files in my site seems to come from the static subdomain. So far so good. But i can reach them from the example.com too. How can i prevent example.com to see the static content?

And also how can i disable access to the dynamic content from sub-domain?

random373839
  • 121
  • 1
  • 1
  • 4
  • Can you show a "curl -i" of the request? Rewrite sends a redirect to the client. You should also read this https://www.nginx.com/blog/creating-nginx-rewrite-rules/ – Tim Sep 21 '16 at 22:07
  • If i curl -i to the static.example.com/style.css the response is 301 Moved Permanently. If i make a request to the example.com/style.css the response is 200 OK. – random373839 Sep 21 '16 at 22:42
  • That suggests to me that you've set things up incorrectly. The static subdomain is forwarding to the main domain and the main domain is serving the images. You need to post your full Nginx configuration if you want further help. I don't bother with cookieless domains personally, even though I like fast websites, partly because I use http/2. This article is somewhat interesting http://www.ravelrumba.com/blog/static-cookieless-domain/ – Tim Sep 21 '16 at 22:58
  • You could also use CloudFlare free plan to serve your static content, brief article about that here https://support.cloudflare.com/hc/en-us/articles/200169816-Can-I-serve-a-cookieless-domain-or-subdomain-through-CloudFlare- – Tim Sep 21 '16 at 22:59
  • Look to me like you're still redirecting from the subdomain to the main domain, against your stated objective. I'm surprised there's duplicate content, this rule should only apply to static content. – Tim Sep 22 '16 at 00:49
  • Nope, no redirection. Now images and other static files directly comes from the static sub domain. – random373839 Sep 22 '16 at 00:51

0 Answers0