I have a website set up for my organisation under www.mycompany.com (running on Amazon S3). I also have a Wordpress blog set up under blog.mycompany.com (running on a separate LAMP server).

For SEO purposes, our marketing department has asked to set up www.mycompany.com/blog to go to our blog main page.

Our website is currently hosted on an Amazon S3 bucket, behind Amazon Cloudfront. I have managed to set up S3/CloudFront redirections successfully so that a basic redirection happens automatically, e.g.:

www.mycompany.com/blog -> blog.mycompany.com/blog

www.mycompany.com/blog/my-article -> blog.mycompany.com/blog/my-article

Which is all fine, except for the fact that Wordpress shows blog.mycompany.com as the subdomain.

Is there any way that we can still show in the URL bar the www subdomain in place of blog? e.g. so it still shows www.mycompany.com/blog/my-article ?

Is there some way we can use mod_rewrite or similar to alter the URL for the Wordpress site?

  • Something isnt right here, you couldnt pissibly be hosting a PHP application, WordPress, on an S3 bucket – Vinnie James Jan 22 '17 at 18:20
  • Sorry - I should explained more clearly. www.mycompany.com is hosted on S3 (plain HTML site), and blog.mycompany.com is on another server altogether that is running a LAMP stack. What I would like is to redirect the /blog subfolder from my S3 site to the LAMP box without changing the www subdomain. – CyberFerret Jan 23 '17 at 6:41
  • Its not possible, the DNS for a domain, or subdomain, can only point to one place. If you were to try to rewrite the blog url to the www url it would just send you back to the www site – Vinnie James Jan 23 '17 at 7:36
  • 1
    An easier option would be: 1) To move the static site to the main server directory (www / public_html or whatever) and host it there. 2) And then I would move the WordPress instance to a sub-folder, www.example.com/blog – See this: codex.wordpress.org/Giving_WordPress_Its_Own_Directory – user23355 Nov 20 '17 at 6:24
  • @CyberFerret I need to do the same thing. Did you find a workaround for this? Thanks! – ianaya89 Nov 27 '19 at 14:05

You are using Cloudfront in front of S3, so in order to mix in 2 sources of content you need to

  1. on your blog.mycompany.com - add rewrites of blog/* -> /* so that your blog can handle blog.mycompany.com/blog/ urls well.

  2. add new blog.mycompany.com as an Origin in "Origins and Origin Groups" tab.

  3. add new "Behavior" for /blog* path pattern and point it to your newly created "blog.mycompany.com" origin.

  4. if you get redirects from blog (e.g. WPMU can do that) - hack $_SERVER hostname variable in your wp-config.php and replace it

|improve this answer|||||
  • I'm doing something similar as the OP, and tried out your suggestion, @WowPress.host, and it very nearly works, except for one thing: the Cloudfront error page! for everything in the root, I need the "error page" to be /index.html (an Angular SPA; index.html is its front-controller), but it seems that when a URL within /blog/ fails, Cloudfront passes it to /index.html! how can we give 404s within /blog/ a different "error page"? – Ben Mar 26 '19 at 20:12
  • check access logs of your /blog/ server. when you call /blog/page-that-doesnt-exists - it should be present in your access log with exactly that uri. afterwards wordpress rewrites it to index.php (see you .htaccess). I guess your wp rewrites it to /index.php instead of /blog/index.php and minor modification required there in .htaccess – WowPress.host Mar 27 '19 at 9:47

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.