My CDN domain is set to www.mysite.com, and it reads from origin.mysite.com. mod_dir is enabled on apache, and so any request without a trailing slash is redirected with a 301 to the equivalent URL with a trailing slash.

The issue is that when someone goes to www.mysite.com/somepage I would expect them to get redirected to www.mysite.com/somepage/, but apache issues a redirect that includes the domain name too, so the redirect issued from apache is actually origin.mysite.com/somepage/ and the user now ends up on origin.mysite.com domain, and whole point of CDN is now lost.

I tried DirectorySlash off but that leads to numerous other problems. The solution I can think of is to have the redirect issue a relative URL, and I am not able to figure out if that is doable at all.

  • 1
    What does the apache httpd config look like (UseCanonicalName, ServerName, etc) and what is the value of the Host header sent by the CDN? – Håkan Lindqvist Jan 11 '16 at 7:16
  • UseCanonicalName is Off (default), and so ServerName doesn't matter that much. I fixed it like this - created a handler in my server that redirects requests coming to /redirect/somepage to www.mysite.com/somepage/, Then in my CDN i created a specific rule to look up requests specifically coming to www.mysite.com/somepage from a new origin, that has /redirect as the base url. The request now goes from www.mysite.com/somepage to origin.mysite.com/redirect/somepage which then redirects to www.mysite.com/somepage/. Convoluted, but works - I needed it only for specific paths – merlinbeard Jan 13 '16 at 7:57
  • Otherwise it sounds like turning UseCanonicalName on could have been a less convoluted solution, if the CDN changes the Host header compared to what the original client requested? – Håkan Lindqvist Jan 13 '16 at 8:11
  • True - But I was scared that setting the canonical name to same as the CDN domain might result in a infinite loop for some requests (not sure about it) - will need to test a bit more. It is probably the better solution in the longer term. Appreciate your advice :-) – merlinbeard Jan 14 '16 at 8:48

I had the same problem.

I fixed the issue changing some wordpress parameters.

In the elasticbeanstalk I set the parameter CUSTOM_URL for my custom domain and in the file /var/www/html/wp-includes/load.php I set the parameters HTTP_HOST and SERVER_NAME to same value of CUSTOM_URL, and it resolved the redirect to elasticbeanstalk url.



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.