If you change the name or location of pages on your website, a 301 redirect allows you to seamlessly guide visitors and search engine crawlers to your updated pages while preserving your search engine ranking.
For instance, you can send users from oldpage.php (.asp or .jsp) to “http://www.newdomain.com/newpage.html” while maintaining your SEO ranking and backlinks.
Utilize the code provided below to guide traffic to your pages through a 301 Redirect.
Note: In the code samples provided below, substitute “oldpagename” with the name of the previous Web page from which you wish to direct traffic, and replace “newpage.html” with the name of the new Web page that you want to direct traffic to.
PHP
Save this as oldpagename.php
<?php> header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.newdomain.com/newpage.html"); exit(); ?>
ASP
Save this as oldpagename.asp
<%@ Language=VBScript %> <% Response.Status="301 Moved Permanently" Response.AddHeader "Location", "http://www.new-url.com" %>
ASP.NET
Save this as oldpagename.aspx
<script language="c#" 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>
.htaccess
When operating a Linux server that has the Apache Mod-Rewrite module activated, you can set up a .htaccess file to redirect every request to coolexample.com to www.coolexample.com, where “coolexample.com” represents your domain. Place the .htaccess file in the root directory of your old website, which is the same location as your index file. You can create a .htaccess file using the following code:
RewriteEngine on rewritecond %{http_host} ^coolexample.com [nc] rewriterule ^(.*)$ http://www.coolexample.com/$1 [r=301,nc]
IIS on VPS or dedicated server
When using a Windows server, you can redirect to a 301 page using IIS.
- In the Internet Services Manager, select the file or folder you want to redirect.
- From the right-click menu, select a redirection to a URL.
- Specify the file name of the page to which you want to redirect.
- Select The exact URL entered above.
- Select A permanent redirection for this resource.
- Click Apply.
Thanks for visiting. For queries and suggestions, emails are welcome at learnweb@hostingcolumn.com.
Subscribe to Hosting Column for the latest updates and posts.