301 Redirect: How to create Redirects and allow Subdomains

Using a 301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. Here’s how you can always redirect to the WWW version of your site while maintaining the use of subdomains.

Redirection is a way to forward users and search engines to a URL other than the one they originally requested. A 301 redirect indicates to the search engines that a page has permanent moved. An issue you may run into with search engines is that www.mysite.com and mysite.com appear the same; this can lead the search engines to believe that there is duplicate content on your site. Whenever content on a site can be found at multiple URLs, it should be canonicalized for search engines. An example of how your content can appear to be duplicate is if your www and non-www versions of your site go to the same article. For example, if both of the following actually point to the same article, you need to implement a 301 redirect:

http://www.mysite.com/myreallycoolarticle

http://mysite.com/myreallycoolarticle

When both links contain the same content search engines might not know which version to include/exclude from their index or which version to rank for query results. The bottom line is that having both available can hurt your SEO rankings. By using a 301 redirect you essentially tell the search engines to always use one over the other. Doing so means that the two pages (while technically the same) no longer compete with one another for ranking.

If you’d like to identify if you have duplicate content issues I’d recommend reading over this excellent article at Yoast.com. Yoast is considered an SEO expert and his article on duplicate content outlines simple ways to use Google Webmaster Tools to see if you’re being double indexed. If you’re curious about the details of how Google responds to 301 redirects just start reading Matt Cutt’s articles on 301’s, SEO, etc. He’s the man in charge of the Search Quality group at Google; he specializes in search engine optimization.

It turns out doing a 301 redirect is pretty simple, the primary rule to keep in mind is that you need to pick one or the other. Either always use WWW or never use WWW. I chose to use WWW, just because I always have. Some will argue that a non-WWW version looks better because the URL is shorter, and while visually that’s true, it won’t make a difference to the search engines.

You can find a plethora of examples of 301 redirects all over the net; so I won’t show a bunch of examples. A simple Google query will find you a ton of them. The problem I ran into is that I wanted to maintain my www but I ALSO use subdomains. Every example I found would redirect ALL non-WWW traffic to the WWW version of my site. One reason I use subdomains is so that I can place my images on images.paulspoerry.com and my page content on www.paulspoerry.com. By default the images of your site are hosted in the same domain as your content and this will slow down your page speed. Why? Almost all browsers create a maximum of two-four connections when downloading a page from your server. So if your page contains more than one image hosting those images in another another domain will allow a browser to download them in parallel with your main domain.

The solution to 301 redirects to WWW, that maintains the use of a subdomain is the following:

The code above tells the server to indicate a permanent redirect of all non-WWW traffic to it’s WWW counterpart while allowing the use of subdomains. So “https://paulspoerry.com/myarticle” will always go to “https://www.paulspoerry.com/myarticle”. It will not modify the request if a subdomain (ex: http://images.paulspoerry.com) is present. FYI, the [NC] is important as it specifies that case isn’t important. It tells incoming requests that “PaulSpoerry.com” (mixed case) and “paulspoerry.com” (lower case) are the same.

So there you go, add the above to your .htaccess file via FTP or CPanel, replacing “yourdomainname” with YOUR domain name. With the rules above you’ll be able to redirect non-WWW requests to it’s WWW counterpart while maintaining the use of subdomains. Once you’ve made the change you can test your redirection with Search Engine Friendly Redirect Checker.

About Paul Spoerry

I’m a groovy cat who’s into technology, Eastern Thought, and house music. I’m a proud and dedicated father to the coolest little guy on the planet (seriously, I'm NOT biased). I’m fascinated by ninjas, the Internet, and anybody who can balance objects on their nose for long periods of time.

I have a utility belt full of programming languages and a database of all my knowledge on databases... I practice code fu. Oh, I've also done actual Kung Fu, and have a black belt in Tae Kwon Do.

Hey Barry… I’m not 100% because I do the opposite…. only because I started that way and stuck with it. If I setup a new one today I’d go with a non-WWW version. That said this below should work to always redirect to a non-www domain and I think is a bit simpler.