jQuery to redirect page to URL that serves as reverse proxy to the page?

180 Views Asked by At

Let's say there's a domain, xyz.com, registered and managed at DNSSimple. A Rails application is configured to serve a website at https://www.xyzDOTcom. There's also a sub-domain, https://get.xyzDOTcom that is configured to serve several landing pages set up using Unbounce.

Now, the SEO guy wants all the Unbounce pages to be made accessible via https://www.xyzDOTcom/storage/PAGE. I implemented this by adding Rack's reverse-proxy to the config.ru.

Problem - The SEO guy also wants the existing https://get.xyzDOTcom/PAGE URLs to redirect (301) to their corresponding https://www.xyzDOTcom/storage/PAGE counterparts. Unbounce allows embedding custom Javascript blogs to its pages, so I tried window.location = , window.location.replace(), window.location.href = etc, but they all resulted in an infinite redirect loop when trying to access https://get.xyzDOTcom/PAGE.

How do I achieve this 301 redirect of https://get.xyzDOTcom/PAGE to the corresponding reverse-proxy https://www.xyzDOTcom/storage/PAGE?

1

There are 1 best solutions below

1
claasz On

How about

  • Create a new subdomain get2.xyzDOTcom
  • Configure Unbounce to use get2.xyzDOTcom instead of get.xyzDOTcom
  • Configure your Rails app to reverse proxy to get2.xyzDOTcom
  • Setup a new web server for get.xyzDOTcom
  • Let the new web server redirect (301) to www.xyzDOTcom

Note: If the whole exercise is because of SEO, it might be a bad idea to do a JavaScript redirect anyway.

Note 2: Don't know if that is an option for you, but Cloudflare Page Rules would make this a no-brainer.