301 permanent redirect in PHP

Discussion in 'Search Engine Optimization (SEO)' started by coderzone, Feb 24, 2006.

  1. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    Whenever we change the names of any files on webserver its better to make a 301 permanent redirect from the old URL to the new URL and for Linux server you can use the .htaccess to make the permanent redirect. I find a disadvantage of this as it is very much dependent on the OS of the server and if you are changing hosts then there could be a problem of old URL not being redirected and so its better to put the redirection into the code. Here are the code snippets to achive the same.
    PHP
    PHP:
    <?
      
    Header"HTTP/1.1 301 Moved Permanently" );
      
    Header"Location: http://www.newdomain.com" );
    ?> 
     
  2. aspguy

    aspguy New Member

    Joined:
    May 2, 2005
    Messages:
    58
    Likes Received:
    1
    Trophy Points:
    0
    Re: 301 permanent redirect in ASP and ASP.NET

    In ASP.NET
    Code:
    <script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
      Response.Status = "301 Moved Permanently";
      Response.AddHeader("Location","http://www.newdomain.com/");
    }
    </script>
    and in ASP
    Code:
    Response.Clear
    Response.Status = 301
    Response.AddHeader "Location", "newUserLogin.asp"
    Response.Flush
    Response.End
     
    Last edited: Feb 24, 2006
  3. jspguy

    jspguy New Member

    Joined:
    May 2, 2005
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Re: 301 permanent redirect in JSP

    Code:
    response.sendError(response.SC_MOVED_PERMANENTLY, "/newURL.jsp");
     
    Last edited: Feb 24, 2006
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Edited title of asp redirect and jsp redirect post.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice