nystudio107 / craft-retour

Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website
https://nystudio107.com/plugins/retour
Other
38 stars 26 forks source link

Some redirects stopped working after a move to Servd #312

Closed mattbloomfield closed 2 months ago

mattbloomfield commented 2 months ago

Question

Andrew,

We ran into an interesting problem recently after moving from Platform.sh to Servd. Some background info is warranted:

We run two different sites on the same domain (www.uschamber.com). To do this, we have our DNS pointed at Fastly, and then Fastly, based off the path, chooses the correct backend to handle the request. When we choose a Servd backend we override the host that is sent to Servd so that it thinks it is the servd.dev domain they provide to us. This is what allows Servd to handle their own routing.

We have a redirect in our main site that is simply catching /tm and redirecting to http://clients.theygsgroup.com/uscc/tm/

However, after our move to Servd we found it was redirecting to https://www.uschamber.com/http:/clients.theygsgroup.com/uscc/tm

The redirect chain as reported by a curl request looked like this:

http://www.uschamber.com/tm to https://www.uschamber.com/tm to https://www.uschamber.com/http://clients.theygsgroup.com/uscc/tm to https://www.uschamber.com/http:/clients.theygsgroup.com/uscc/tm

In Retour it was setup like this: image

We fixed the issue by changing from Path Only to Full URL and then updating the value of Legacy URL Pattern from /tm to https://www.uschamber.com/tm

But I am curious - why would this have happened? Is it due to the way Retour is picking up the host?

khalwat commented 2 months ago

So this looks key to me: https://www.uschamber.com/http:/clients.theygsgroup.com/uscc/tm

Note the http:/ -- I'm guessing somewhere, some config (Craft or Servd) is missing a slash in the site configuration...

mattbloomfield commented 2 months ago

Note the redirect chain I posted - it seems that craft strips that and redirects it, but the https://www.uschamber.com/http://clients.theygsgroup.com/uscc/tm request should have never happened in the first place

khalwat commented 2 months ago

Agreed. Hey can you try this out, there have been some changes in how things work to solve another issue:

https://github.com/nystudio107/craft-retour/issues/288

Craft CMS 3:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-retour": "dev-develop as 3.2.20”,

Then do a composer clear-cache && composer update

…..

Craft CMS 4:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-retour": "dev-develop-v4 as 4.1.20”,

Then do a composer clear-cache && composer update

…..

Craft CMS 5:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-retour": "dev-develop-v5 as 5.0.4”,

Then do a composer clear-cache && composer update

With the change, you should no longer need to do a Full URL match for your case. What Retour does now is it will find the path prefix that is used by a Site's baseUrl and strip it from the incoming 404 path, and then use that in the rest of the redirect matching chain.

So for example, if the request URL is http://example.com/es/blog/this-does-not-exist, the actual path is /es/blog/this-does-not-exist but Retour will reduce it to /blog/this-does-not-exist and then do the redirect matching.