How to do 301 Redirect in different language

301-redirect301 redirect is one of the excellent technique when we want to redirect from one url to another permanently. This “301” moved permanently code which tells search engine that the url is permanently changed and help to transfer 90-99% of link juice to new url. 301 redirect is most effective and search engine friendly method of url redirection.

Here are some 301 redirect method for different programming language and .htaccess

IIS Redirect

  • In internet services(IS) manager, right click on the file or folder you want to redirect
  • Select the radio titled “a redirection to a URL”.
  • Enter the redirection page or url.
  • Check “The exact url entered above” and the “A permanent redirection for this resource”
  • Click on ‘Apply’

ColdFusion Redirect

<.cfheader statuscode=”301″ statustext=”Moved permanently”>
<.cfheader name=”Location” value=”http://www.new-url.com”>

PHP Redirect

<?
Header( “HTTP/1.1 301 Moved Permanently” );
Header( “Location: http://www.new-url.com” );
?>

ASP Redirect

<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://www.new-url.com/”
%>

ASP .NET Redirect

<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>

JSP (Java) Redirect

<%
response.setStatus(301);
response.setHeader( “Location”, “http://www.new-url.com/” );
response.setHeader( “Connection”, “close” );
%>

CGI PERL Redirect

$q = new CGI;
print $q->redirect(“http://www.new-url.com/”);

Ruby on Rails Redirect

def old_action
headers[“Status”] = “301 Moved Permanently”
redirect_to “http://www.new-url.com/”
end

Redirect Old domain to New domain using htaccess redirect

Just create a file called .htaccess on the root of domain and put the following code on it and upload.

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

REPLACE www.yourdomain.com in the above code with your actual domain name.

In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.

Redirect to www using htaccess redirect

Just create a file called .htaccess on the root of domain and put the following code on it and upload.

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

REPLACE yourdomain.com and www.domain.com with your actual domain name.

Some more .htaccess technique and method

 #Redirect all pages from olddomain.com to newdomain.com

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR] RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L] 

#Prevent subfolder loading. This goes
# in htaccess for the primary domain
RewriteCond %{HTTP_HOST} ^primary\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.primary\.com$
RewriteRule ^addon\.com\/?(.*)$ “http\:\/\/www\.addon\.com\/$1” [R=301,L]
#Prevent subdomain name loading.
#This goes in htaccess for the primary domain
RewriteCond %{HTTP_HOST} ^subname\.primary\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.subname\.primary\.com$
RewriteRule ^(.*)$ “http\:\/\/www\.addon\.com\/$1” [R=301,L]
# Never use www in the domain
# Replace ‘example.com’ with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?example\.com)$ [NC] RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
# Always use www in the domain
# Replace ‘example.com’ with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L]
# Set a default home directory, (this subfolder always loads)
# Replace ‘folder’ with your subfolder name
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /folder/ [R=301,L] </IfModule>
# Rename a directory and force visitors to the new name
# Replace ‘old’ with your old folder name Replace ‘new’ with your new folder name
RewriteEngine on
RewriteRule ^/?old([a-z/.]*)$ /new$1 [R=301,L]
# Always use https for secure connections
# Replace ‘www.example.com’ with your domain name (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
# Block traffic from multiple referrers
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite\.com [NC,OR] RewriteCond %{HTTP_REFERER} badforum\.com [NC,OR] RewriteCond %{HTTP_REFERER} badsearchengine\.com [NC] RewriteRule .* – [F]
#Do not allow these file types to be called
RewriteEngine on
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|exe|swf)$ – [F,NC]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.