THE 301 REDIRECT: POPULAR TEMPLATES

Each SEO specialist faces necessity of using the 301 redirect which becomes important if you are going to change URLs of your pages, remove duplicate content, redirect users to another domain, and so on. You can find the most popular patterns of the 301 redirect in this article.

Since Apache is the most widespread web server, all templates listed in this article will concern it. To be more specific, templates should be prescribed in a root file .htaccess. Make sure that the module mod_rewrite (a file httpd.conf) is connected to Apache before using of the 301 redirects sample.

To use 301 redirect, first you need to specify directives necessary for operation of the module mod_rewrite in the first few lines of .htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

Let`s consider rules of typical forwarding.

Redirect from an address with www-prefix to an address without www

Get lost in the search results?

Let Promodo experts help your website index better by optimising your pages, improving your content, and enhancing your linking strategy.

By clicking this button you agree to our terms & conditions

To redirect all pages with www (http://www.site.com.ua/page.html) to pages without www (http://site.com.ua/page.html), use the following template:

RewriteCond %{HTTP_HOST} ^www.site.com.ua$ [NC]
RewriteRule^(.*)$ http://site.com.ua/$1 [R=301,L]

Or a simplified version:

RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Redirect from an address without www to an address with www

You can 301 from pages without www (http://site.com.ua/page.html) to pages with www (http://www.site.com.ua/page.html) in almost the similar way as in the previous example. Just change the position of www:

RewriteCond %{HTTP_HOST} ^site.com.ua$ [NC]
RewriteRule^(.*)$ http://www.site.com.ua/$1 [R=301,L]

Or an alternative simplified variant:

RewriteCond %{HTTP_HOST} !^www.(.*) [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

It is also worth mentioning that sometimes the rules work even if dots are not screened with a backslash, but don`t abuse it, because this can lead to errors at some servers.

Redirect from an index page to a site root

This type of redirect often causes problems if you use CMS, which redirects all site requests to an index page. Adding directives to .htaccess file will lead to a cycle of endless redirects. The easiest way is to insert a small snippet to the top of an index page (egindex.php):

if($_SERVER[‘REQUEST_URI’] ==  ‘/index.php’) {
header(“Location: /”,TRUE,301);
exit();
}

Thus, addresses are compared while requesting an index page, and if the requested address is, for example, http://site.ua/index.php, then the condition is triggered and redirection to a root of the site http://site.ua/ is performed. If a site doesn’t redirect all requests to index.php, you can use the following template for mod_rewrite:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.php$ http://site.com.ua/ [R=301,L]

The same redirect can be used for other extensions of the main page as well, such as index.html, or, for example, index.phtml.

Redirect from a subdomain to a subfolder

This kind of 301 redirect is needed to redirect multiple similar pages from a sub-domain to new addresses which have a certain pattern. This problem often arises, for example, when some language versions of a site are available on a subdomain and in a subfolder of your main domain.

For example, you have a page with an address http://eng.site.com.ua/page.html and we need to redirect it to a duplicated page http://site.com.ua/eng/page.html. We use the following template (a file prescribed for .htaccess is a subdomain) for this purpose:

RewriteCond %{HTTP_HOST} ^www.eng.site.com.ua [OR]
RewriteCond %{HTTP_HOST} ^eng.site.com.ua
RewriteRule^(.*)$ http://www.site.com.ua/eng/$1 [L,R=301
]

Redirect from a domain subfolder to a subdomain

If it is necessary to redirect a user from a subfolder to a subdomain, use the following template:

RewriteCond %{HTTP_HOST} ^site.com.ua$ [NC] RewriteRule ^/eng/(.*)$ http://eng.site.com.ua/$1 [R=301,L]

Redirect from one file extensions to other

When you change an engine or while changing a static version of a site to dynamic, you should leave pages available by old addresses. For this purpose it is necessary to redirect old addresses of pages to pages with new extension.

RewriteRule^(.*).html$ $1.php [R=301,L]

Redirect to another site

While creating a new site, it is sometimes necessary to make it as a basic mirror, redirecting users from an old domain to a new one. You may use a template below:

RewriteCond %{HTTP_HOST} ^oldsite.com.ua
RewriteRule^(.*)$ http://newsite.com.ua/$1 [R=301,L]

All pages of an old domain will be redirected to corresponding pages of a new one.

301 redirect of dynamic pages

When upgrading a dynamic site and creating CNC addresses a need to redirect old pages with the ID parameters to a new CNC often appears. For example, to redirect a page from http://site.com.ua/page.php?id=13 to a new page http://site.com.ua/newname.html, use the following structure:

RewriteCond %{QUERY_STRING} ^id=13$ RewriteRule ^/page.php$ http://site.com.ua/newname.html [L,R=301]

Redirects of Cyrillic and RF domains

All of the rules above are valid for domains written in Cyrillic. However, if you create a redirect it is better to replace Cyrillic domains with so-called Punycode. You can use one of online converting services by WhiteWhois.

The obtained encoded domain name can be easily applied to any template of the 301 redirect, as described above.

Despite the abundance of different templates and ready-made solutions, the best solution independent exploration of mod_rewrite syntax principles and its directives. Understanding basic structures allows you to easily write redirects yourself, as well as read and correct the existing .htaccess files.

Leave a Reply

avatar
  Subscribe  
Notify of

Recent posts

PPC Case Study: How to increase brand awareness with digital promotion & TV ads

October 22, 2020

TV advertising is still the most effective channel for developing a brand in both the short and long term. Despite this, launching TV flights* is up to 60%  more profitable in combination with an online promotion. *In marketing, flighting is a process where advertisers schedule messages to run during optimal periods of time, followed by Continue reading >

6 Metrics for Ecommerce Websites You Didn’t Know About

October 16, 2020

Keeping track of the number of visitors, orders, and the bounce rate has long been insufficient to effectively develop an online store. Pavel Kapelyushny, Deputy Head of Customer Development at Promodo shares six important metrics that eCommerce marketers and business owners should regularly monitor. Percentage of missed impressions in the search Let’s say people place Continue reading >

PPC Case Study: How to Increase Sales in the Online Store During the Lockdown

September 22, 2020

Many online marketers habitually classify PPC ads as a tool for boosting direct sales. However, this type of advertising can be an effective means to increase brand awareness. In this article, we share the case of a premium audio equipment retailer from the UK. Client Premium Sound is a Hi-Fi & home cinema equipment retailer Continue reading >

The Ultimate Guide on Google Shopping Campaigns

September 11, 2020

In 2019 Adwords shopping campaigns generated 29% more revenue year-over-year. Whereas paid search revenue increased by only 13% over that period. Is it possible to increase conversions from Shopping ads in 2020? – Yes! Learn the best practices from real cases explained by our PPC Specialist Vladislav Platonov. What is Google Shopping? Google Shopping is Continue reading >

Let's get the ball rolling

Please fill in this short form and we will be in touch with you soon

For any questions [email protected]

UK | USA | EST

+44 (0) 20 313 766 81
+44 7852 537715

Lincoln
The Terrace AT5,
Grantham Street,
LN2 1BD

+1 347 809 34 86

Las Vegas
6920 S. CIMARRON RD.,
Suite 100,
NV 89113

Tallinn
Roosikrantsi 2-K230,
Kesklinna linnaosa,
Harju maakond,
Tallinn 10119

CEE Ecommerce Report 2019

Based on the analytics data of 292 websites

enter correct name, please
enter correct e-mail, please
SEO

THE 301 REDIRECT: POPULAR TEMPLATES

0
start now

Start now