Very Simple Redirect! (Meta Refresh)

Discussion in 'Programming' started by Elliot02, Sep 13, 2017.

  1. Elliot02

    Elliot02 Aspirant

    38
    13
    +11
    Instant Redirect:
    Code:
    <html>       
       <title>The Admin Zone!</title>     
       <meta http-equiv="refresh" content="0;URL='http://theadminzone.com/'" />   
    </html> 
    If you have your forums in say, /forums/ and want to redirect to it you can use this simple redirect. It helps because you can add little things to this code to run before going. For example, you could do something to give a little bit of information.
    Code:
    <html>      
       <title>The Admin Zone!</title>     
       <meta http-equiv="refresh" content="5;URL='http://theadminzone.com/'" /> 
    <b> Please make sure to be respectful! </b>  
    </html>
    By changing content="0 to 5 this will add 5 seconds until the redirect initiates. This will allow the user time to read the <b> Please make sure to be respectful! </b>

    this is super simple, and there probably is a better way but this is how i've done it.
     
  2. mysiteguy

    mysiteguy Devotee

    2,144
    887
    +1,438
    From an SEO perspective a 301 redirect is the way to go.
     
  3. Elliot02

    Elliot02 Aspirant

    38
    13
    +11
    If my understanding is correct, then a 301 redirect is only more beneficial if you had content on the page previously that ranked well.
     
  4. Ryan Ashbrook

    Ryan Ashbrook IPS Developer

    3,624
    1,127
    +566
    A 301 ("Moved Permanently") will always be beneficial, and is the correct response code to use in this case - you are essentially telling both search engines and browsers that "this page used to live here, but now it permanently lives in this location instead." Ranking of the previous page doesn't necessarily matter in this case, because the response applies to more than just search engines which nets a few benefits - namely:
    1. SERP's will automatically update their indexes with the new location once it learns that the content has moved.
    2. Browsers can cache that redirect, because it now knows that the content has been moved, so it saves an unnecessary request to the server to figure that out and it can just send the user to that location on its own.
    The only downside to this is that you might see a temporary decline in search engine rankings for a period of time, but it almost always recovers. The only time I've seen it not recover is if the redirects were set up improperly. That is why it is important to consider the implications of mass-moving entire sections of a site before you actually do it.

    I also would not recommend delaying the redirect either - generally speaking, unless you have a very specific message that you need to show (usually after the user has taken a specific action - such as updating their profile, or sending a message to a support system), then you should always redirect instantly. Otherwise, it can result in a bad user experience if the user has to wait before they are taken to where they need to go. If a wait period does need to be used, then it should generally not be more than one to two seconds at max.
     
  5. Elliot02

    Elliot02 Aspirant

    38
    13
    +11
    So you're saying that a 301 is beneficial in all cases, even if the content never existed in the first place?
     
  6. Ryan Ashbrook

    Ryan Ashbrook IPS Developer

    3,624
    1,127
    +566
    No - only when something has existed and was then moved. If it never existed than a 302 Found or 308 Permanent Redirect should be used.

    My point was that you should always issue a code regardless (as in, previous page rank would not be a factor either), and it should be appropriate in context. Your code would issue a 200 OK header. I don’t typically recommend using meta refreshes outside of pages that need to continually refresh their content, and JavaScript is not available to do it via Ajax. In this instance, a meta refresh will always use more resources because it has to do a full request again.
     
  7. mysiteguy

    mysiteguy Devotee

    2,144
    887
    +1,438
    Use a 302 when you're testing, 301 when you're satisfied everything works right. For a file that never existed a 404 is appropriate. If its a file that did exist but you have no intention of redirecting or replacing it, a 410 (gone) is appropriate.
     
  8. Ryan Ashbrook

    Ryan Ashbrook IPS Developer

    3,624
    1,127
    +566
    Yes - although, if a file does exist, but in another location, then 302 is more appropriate. It says "Yes, this does exist, but it's located here, not where you requested, but may change in the future." As of HTTP/1.1, at least - HTTP/1.0 defines a 302 as Temporary Redirect which creates a conflict between the two verbs.

    For something that legitimately does not exist, with no alternative, then a 404 (or 403, if the requested resource is only available to specific users) is appropriate.
     
Verification:
Draft saved Draft deleted