0

I have an AWS load balancer that does a 301 redirect from URL test1 to URL test2. For the most part the redirect works as expected, however, when I have a script with type=module, then test1 isn't redirected to test2. Is this by design, and is there any way to get it properly redirected?

script type=module src=https://test1....

5
  • 1
    What do you see on the Access-log of the load balancer? Since it is for a script, it might be due to CORS which is not letting to proceed with the redirect as the new domain is not in the allowed list Commented Apr 9, 2024 at 2:29
  • Yes. I'm not sure how to add the domain onto the allowed list within AWS. Can you advise? Also, all other cases of the redirect do work as expected. Commented Apr 10, 2024 at 12:53
  • ALB doesn't support adjusting of headers now. There are different ways to deal with this. Quicker one will be to make sure you that you are using relative url in your webpage than absolute. Example for relative: src="/scripts/script.js" and for absolute is src="https://example.com/scripts/script.js". In the code section you are using, change it to script type=module src=/<url path to script>. The same applies for CSS files as well Commented Apr 10, 2024 at 22:34
  • Missed to mention on how the change to relative will help. When the initial index page is requested, it will be getting redirected to "test2". Browser will then go to "test2" to get the index page which is where the JS and CSS files are mentioned. If you are using relative option, browser will consider the domain for the full url of the file as test2. This way, the request for the script file will be directly going to test2. Absolute option usually used when you are required to fetch content from a different domain which is not your case. Commented Apr 10, 2024 at 22:45
  • excellent info! I think we do actually need absolute, and were running into CORS issues. Any thought on how to work around this? Commented Apr 12, 2024 at 12:51

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.