Question

I have those two lines in htaccess to require www.*

<IfModule mod_rewrite.c>
    RewriteEngine On
    #require www
    RewriteCond %{HTTP_HOST} ^oisie\.com
    RewriteRule ^ http://www.oisiecom%{REQUEST_URI} [L,R=301]
</IfModule>

I'm adding Amazon Web Services (AWS) CloudFront CDN and it's not working because of 301 redirects.

If I go straigt to

http://XXXXXXXXX.cloudfront.net/img/preloader.gif

I get redirected to my site's real domain e.g. oisie.com

How to miss www.* redirects when request is comming from *.cloudfront.net?

You can check for details at http://www.oisie.com/en

Was it helpful?

Solution

I've forgot about this question already, but I've fixed the problem. I can't remember exact steps, what I've done, but now i have a subdomain for static contents - js, css etc. it points to same directory as it would be normal domain. eg:

http://s.oisie.com/img/oisie.png

is same url as

http://www.oisie.com/img/oisie.png

In Cloudfront configuration I'm using s.oisie.com domain and it works fine.

So the solution: create virtualhost for static domain, which will be used by cloudfront and use it in cloudfront config (at AWS console).

hope that helps! :)

OTHER TIPS

I had the same issue and I fixed it with below redirect rule in .htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sitename.com$
RewriteRule ^(.*)$ http://www.sitename.com/$1 [R=301]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top