0

When I fetch this URL, which doesn't have the trailing slash:

const url = "https://www.inkandswitch.com/local-first";
const fetchResult = await fetch(url);
console.log("Status:", fetchResult.status);
console.log("HTML:", await fetchResult.text());

The result is:

Status: 200
HTML: <!DOCTYPE html><html><head><title>https://www.inkandswitch.com/local-first/</title><link rel="canonical" href="https://www.inkandswitch.com/local-first/"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=https://www.inkandswitch.com/local-first/" /></head></html>

That's it. No redirect to the canonical URL. However, if you request it from the browser, it can still be redirected to the canonical one. I wonder why would they not return the redirect code?

2
  • The server is returning is returning the same content. Your javascript code is not a browser. It does not treat HTTP responses in the same way as a browser does.
    – symcbean
    Commented Jun 6 at 12:35
  • can you elaborate on that? For instance, the fetch function can still redirect to the correct resource
    – Ooker
    Commented Jun 6 at 17:41

1 Answer 1

1

The biggest reason not to use a 301 redirect code is that your server setup does not support it. Most web hosts do, but occasionally you'll find one that doesn't (as an example off the top of my head, there is no way to do redirect status codes if your website is hosted on GitHub Pages).

Otherwise, if your server setup does allow you to use 301 redirects, then 301 redirects are an all-around better choice than meta refresh redirects.

2
  • There is this line in the response: <meta http-equiv="refresh" content="0; url=https://www.inkandswitch.com/local-first/" />. Does this mean as a directive for the browser to redirect to this page? As the site is likely to use a dedicated server software, I think it's in their ability to set the status code at will.
    – Ooker
    Commented Jun 9 at 9:09
  • Yes, that is a properly written redirect tag. It instructs the browser to redirect the page. And yes, if the server setup allows for 301 redirects instead, definitely use them instead of these meta tags. Commented Jun 9 at 16:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.