I'm facing an issue setting up wordpress with cloudfront.

I've set up all things fine, and it's working, but the problem is that when I send a request, the origin url is displayed in the address bar instead of the cname.

here is my origin vhost configuration :

<VirtualHost *:80>
        ServerAdmin admin@mydomain.com
        ServerName  origin.mydomain.com

        DocumentRoot /var/www/mysite.mydomain.com
        <Directory /var/www/mysite.mydomain.com>
                Options -Indexes MultiViews FollowSymlinks
                Options Indexes FollowSymLinks MultiViews
                #AllowOverride AuthConfig
                AllowOverride None
                Order allow,deny
                allow from all
        <IfModule mod_headers.c>  
                Header unset Server  
                Header unset X-Pingback
                Header unset X-Powered-By  
                Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
        ErrorLog ${APACHE_LOG_DIR}/mysite.mydomain.com/error.log

        CustomLog ${APACHE_LOG_DIR}/mysite.mydomain.com/access.log combined


At the cloudfront side I have this for my distribution settings :

Domain Name : d7jz390azoodb9.cloudfront.net

Origin : origin.mydomain.net

CNAMEs : mysite.mydomain.com

I made DNS registristions so that :

origin.mydomain.com points to the_public_ip_address_of_myserver

mysite.mydomain.com is a cname of d7jz390azoodb9.cloudfront.net

All the above is working fine. My problem is that, when I enter this in my browser : http//mysite.mydomain.com, I get to my wordpress home page, and from the when I try to navigate, for example clicking on "login" (http://mysite.mydomain/wp-login.php), the url dispayed in my address bar at the top of my page is : http://origin.mydomain/wp-login.php instead, which can be then seen by any user.

If I type myself mysite.mydomain/wp-login.php directly in the browser, I get a Not found from cloudfront.

If I replace the ServerName in my vhost configuration by mysite.mydomain.com I get a Miss from cloudfront.

Do someone know to fix this, so that the url seeing by user always remain mysite.mydomain.com?


  • I don't see any URL rewrites, so in that case, do you have any configuration done in WordPress to make WP aware it should use the correct subdomain? – JayMcTee Jul 1 '15 at 10:06
  • Yes @JayMcTee . I did this in my wordpress database : UPDATE wp_options SET option_value = replace(option_value, 'mysite.mydomain.com', 'origin.mydomain.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'mysite.mydomain.com', 'origin.mydomain.com'); UPDATE wp_posts SET post_content = replace(post_content, 'mysite.mydomain.com', 'origin.mydomain.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value,'mysite.mydomain.com', 'origin.mydomain.com'); – nixmind Jul 1 '15 at 10:27
  • And in my vhost/wordpress root directory, I have this in the .htaccess file : # BEGIN WordPress RequestHeader unset Cookie Header unset Set-Cookie Redirect permanent / http://origin.mydomain.com/ # END WordPress – nixmind Jul 1 '15 at 10:37
  • Well, then you are redirecting to origin.mydomain instead of mysite.mydomain: "Redirect permanent / origin.mydomain.com" Did you forget to update that redirect? Instead of a blanket redirect, why not match it only if the wrong host is requested? stackoverflow.com/questions/5553980/… – JayMcTee Jul 1 '15 at 10:41
  • No I put this redirect to solve the issue, but it did notthing. – nixmind Jul 1 '15 at 10:55

The problem was in cloudfront behavior settings.

The configuration I did was good but I told cloudfront not to forward cookies and then the origin server were not receiving any cookie.

I activated all cookies forwarding in cloudfront and it works.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.