When decommissioning servers, I’ve always used DNS CNAMEs or IIS for URL redirects, three clicks and works flawlessly every time. However, we came across a requirement to redirect a bunch of old URLs to a new landing page without an IIS server in the mix.
The most popular solution in this scenario seems to be setting up an S3 Bucket URL redirect. After messing about for a few days, we went looking for a different solution because:
- We needed users to be redirected to a specific URL not just a new server name
- The S3 redirect wouldn’t work for the URLs that have nonstandard HTTP ports (8734 or 8080 for example)
- It didn’t seem to work consistently across browsers, possibly because we had a man-in-the-middle type URL setup
- We didn’t want to set up a bucket for every single URL that needed to be redirected
- There was no option to easily redirect HTTP requests to HTTPS
Enter Alex Chard, who vry casually suggested using an ALB which is a simple, elegant, easy to manage solution. It’s odd that the AWS documentation doesn’t suggest this but it works perfectly. So, thanks, Alex!
This article details how to redirect all user requests to a single URL and how be a bit fancier, and redirect requests to different URLs based on the webpage host headers.
Here’s how to set it up:
- Listeners: create a listener for the ports your old URLs use.
In our case, we needed HTTP over port 8734 but you might have ports on 8080, for instance - If you have source URLs that use HTTPS/443 you can configure a HTTPS listener and attach an SSL cert here as well
- If not, skip past the warning. In our case, the URLs are all HTTP so no 443 listener is needed
- Edit the ALB Listener rules for HTTP/80
- Delete the default “forward to” rule
- Create a new “Redirect to” action
- Populate the action with your new URL and save
- Navigate to EC2 > Load Balancing > Load Balancer > Target Groups
- Find your fake target group and delete it
- Point the DNS CNAMEs for your old/defunct server names to the new Redirect Load Balancer address:
- or wait a few minutes…
- Profit!
- The target group will be deleted once we’re finished, so put anything you like here
- Click through to the end and create the LB
We have a static SharePoint page that informs users that the old page they tried to access no longer exists. In this scenario, every old web server that is decommissioned will be pointed to the new links landing page.
- Edit the ALB Listener rules for HTTP/80
- Delete the default “forward to” rule
- Create a new “Redirect to” action
- Forward all requests to HTTPS/443
happy URL forwarding :)
Simone, Alex & Adrian
To set this up:
This works well if you need all of your URLs and server CNAMEs to point to a single place.
If you need each of your old URLs to point to a new individual location, you can use the same ALB to do this…
Finally, if you can:
If possible, its good practice to redirect all HTTP requests to HTTPS. If you want to set that up:
Originally published at https://medium.com on June 18, 2020.