A couple of my items. Click to view more. I think you need something like this
 

 

1

2008-03-03

301 How to Redirect a Web Page in ASP, ASP.NET or PHP

50200735006880.jpg301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. It’s not that hard to implement and it should preserve your search engine rankings for that particular page. If you have to change file names or move pages around, it’s the safest option. The code “301″ is interpreted as “moved permanently”. If been looking around for the ways on how to do this. So this is what i’ve found:

ASP.NET

1
2
3
4
5
6
<script runat="server">
private void Page_Load(object sender, System.EventArgs e){
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>

Classic ASP (ASP3.0)

1
2
3
4
5
6
<%@ Language=VBScript%>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
Response.End
%>

PHP Redirect

1
2
3
4
5
<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
exit();
?>

Redirect Old domain to New domain (htaccess redirect)

The code belew, which you place into a file called .htaccess in the root folder of your old domain, will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.

The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

1
2
3
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.new-domain-name.com/$1 [R=301,L]

NOTE: REPLACE www.new-domain-name.com in the above code with your actual domain name.

NOTE: This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Redirect to www (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com

As with the last example, the .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

1
2
3
4
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

NOTE: Replace domain.com with your domain name

NOTE: Both of these last examples ONLY works on Linux servers having the Apache Mod-Rewrite moduled enabled.

And there you have it. You can Test your redirection with Search Engine Friendly Redirect Checker

This entry was posted on Monday, March 3rd, 2008 at 2:38 pm and is filed under Linux, Tutorial. You can follow any responses to this entry through the RSS 2.0 feed.You can leave a response, or trackback from your own site.

There are One Response to “ 301 How to Redirect a Web Page in ASP, ASP.NET or PHP ”

1

Frank Pipolo Internet Marketing Says

Even though this post is older it really holds the same value today. A 301 redirect is by far the best way you can redirect your site/page. I see so many people who do not perform it correctly. Very nice write up.


Track & Ping backs

    Leave a Reply

     

    recent projects

    My Boy (1)

    Title : My Boy (1)
    Media: Canon EOS 350D DSLR, Adobe Lightroom, Photoshop
    Description : A day out in the park with my world.

    Tasmania Corrective Services Badge

    Title : Tasmania Corrective Services Badge
    Media: Adobe Illustrator, Stitch
    Description : Badge for the Canine Drug Detection Unit

     

    Webb Martin Consulting Website Concept 1

    Title : Webb Martin Consulting Website Concept 1
    Media: Blog/Website, flash, css, xhtml, php
    Description : Website deisgn for Webb Martin Consulting

    Webb Martin Website Design Concept

    Title : Webb Martin Website Design Concept
    Media: Wordpress, CSS, xhtml, php
    Description : Concept website design for Webb Martin.

     

     

    site tags

     

    meta