HTTP redirects or URL forwarding is a technique for redirecting one URL to another. Often used for avoiding broken links in new sites, or abbreviating URLs, HTTP redirects are a convenient way to preserve traffic and avoid 404 errors. Used incorrectly, however, redirects can cause SEO and performance issues.
In Apache redirects can be accomplished with the mod_alias or mod_rewrite modules. To redirect one url to another you can use a configuration file or the .htaccess file thus:
Redirect 301 /oldurl http://www.sample.com/newurl
The redirect directive of the mod_alias module takes two arguments, the old URL and the new URL. The above redirect instructs all browsers to direct all requests from /oldurl to www.sample.com/newurl. The 301 signifies a permanent redirect, 302 (the default) signifies a temporary redirect.
Canonicalization is the normalization (or standardization) of multiple urls to a single dominant version. For example:
http://www.example.com
http://example.com
http://example.com/
http://www.example.com/?=...
All of the above urls refer to the example.com home page, but a search engine will only consider one of them to be the canonical version of the URL. Having standardized URLs is important for computer security and SEO.
In search engine optimization you want to avoid duplicate content, and diluting your backlinks and pagerank. What you don't want are backlinks pointing to both the non-www and www. versions of your URLs. One way to avoid this is to use a 301 redirect to standardize on one version of your domain. To redirect from non www to www. urls you can use the following code in your .htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
Substitute your domain name for domain.com of course. So requests to http://domain.com will be redirected to http://www.domain.com, standardizing the URLs on the www. version.
One issue we ran into in a recent performance audit was with a 301 redirect going the other way, from www. to non-www URLs. Figure 1 shows the waterfall graph of the target site:
Note that the www.example.edu is redirected to example.edu, with the associated delay. The TTFB is 1.27 seconds in this case. Redirecting the non www. version to www. resulted in a waterfall graph shown in Figure 2.
The TTFB dropped to 0.63 after the redirect. This technique avoids multiple delays shown in Figure 1. The slower the server response, the slower the results will be with the first version.
Standardizing on an authoritative URL form is a best practice for search engine optimization and performance. Avoid duplicate content and first byte delays by canonicalizing your URLs.
By website optimization on 24 Mar 2014 AM