1

I'm a little confused between a 301 redirect, the javascript meta http-equiv="refresh approach and lastly using a 404 which can work out where you wanted to get to and then forward you on.

I can see that a 301 (and a 302) potentially may never pass the original HTML page to the client (it can be handled on the server, such as in IIS or Apache and when it finds the 'new' page to show, only that page is passed to the browser) where as the meta-refresh requires the page to be dished to the browser and then an action takes place (the forwarding).

However, the 404 page may also never be sent to the browser! Consider find a page, IIS can't find it, so dish out the 404. The 404 has some server code, which contains the forwarding logic. Hence, only 1 page will be sent to the browser.

Is the fact the server only returns 1 result (1 HTML page) that makes it a permanent 301 and so either using URL re-writing or the above example of the 404 are identical (identical in that it's treated as a 301)?

If this is the case, how does this actually differ from a 302? Do we need to add some meta information to explain it's a 302 or 301? My research suggests not.

1
  • 1
    The 301, 302 and 404 are examples of the HTTP status code that is sent in the response to the client (ie. browser). The client then knows what the code means. If "the 404 page may also never be sent to the browser" then presumably the browser never sees the 404 status, so as far as the browser is concerned it's a normal page response.
    – DocRoot
    Aug 9, 2017 at 17:18

1 Answer 1

2

I think your question is a bit confusing, probably mainly because you have some terminology mixed up.

A redirect literally just means that a client tried to load a certain URL, and the server redirected them to another page. Whether or not this is the page the user intended has little to do with it from a technical standpoint.

A HTTP Status code is a means for the server to pass on information about the requested page. For example, if a page was not found it sends a code 404 "Not found". Generally when talking about redirects on a server level, people refer to the 301 ("Permanently moved") or 302 ("Temporarily moved") status codes.

If you would set a certain page (e.g. your custom 404.html) to show as your error page, technically the client is redirected from the requested URL to the actual 404 page. However, the status code doesn't change, causing this to be interpreted as a "Not found" for all intents and purposes, even though there has been some kind of redirection going on.


There are several ways to send a status code to the client, among which are using rewrite rules on a server level (Apache/IIS) and sending the headers from within the server-side code that is executed (PHP, Perl, etc).

However, <meta http-equiv="refresh"> is not one of them. This an HTML tag that is interpreted on the client side, after the server has done it's thing. The same goes for any client-side javascript that may redirect the visitor to another URL. This simply works the same way as being on a page and clicking a link to the other page.

To make things a little more confusing, for SEO purposes Google chose to interpret a http-equiv="refresh" with a time-out of 0 seconds (an instant redirect) as a status code 302. This is just their interpretation, and nothing official. From a technical standpoint (you can verify this while watching the network tab of your developer console when loading a page with a refresh on it) it is just a page load (status 200) immediately followed by another page load.

3
  • However, the status code doesn't change, causing this to be interpreted as a "Not found" for all intents and purposes, even though there has been some kind of redirection going on. - Oh dear.... But thanks, but oh dear :S
    – Dave
    Oct 6, 2014 at 10:50
  • If I use URL rewriting at the server level, how is this sending a 301? Is IIS just doing it for me implicity or is this something I can control?
    – Dave
    Oct 6, 2014 at 10:51
  • 1
    I'm not sure about IIS, I know that Apache's mod-rewrite sets an implicit 302 unless you set an explicit code. This might be the same for IIS as well. Oct 6, 2014 at 11:12

Your Answer

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

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