Use .htaccess To Redirect One Domain To Another Domain
Posted by alex in Insights at 11:45 PMI have been using a WordPress plugin for awhile called Pretty Link Pro which provides a ton of awesome features including a link shortener such as tinyurl.com. When using the URL shortener you can actually configure Pretty Link Pro to use a different domain which would be a benefit if your URL is long similar to www.question-defense.com. I have been using link.as so instead of providing shortened links such as http://www.question-defense.com/1ce I can provide links such as http://link.as/1ce which you can see is a lot more user friendly when providing links to others. One thing I wanted to ensure was the fact that Google was not crawling content on the http://link.as URL which is possible simply by Google finding the shortened links on places like Twitter. Below I describe a .htaccess modification that will redirect any traffic to one URL to another while including any trailing text.
Entry In .htaccess That Will Redirect Traffic From One Domain To Another Domain:
# Redirect Link.AS
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^link.as$ [NC]
RewriteRule ^(.*)$ http://www.question-defense.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.link.as$ [NC]
RewriteRule ^(.*)$ http://www.question-defense.com/$1 [R=301,L]
</IfModule>
The 301 used in the RewriteRule statement above states that the URL has been moved permanently so search engines will know not to check the URL used initially but will instead continue to use the URL that they were redirected to instead. In the example above I am redirecting any traffic to link.as to www.question-defense.com as well as any traffic to www.link.as to www.question-defense.com. The main reason for doing this is the fact that search engines will penalize you for duplicate content. If they think that you are providing the same data on multiple domains then you will be penalized in the SEO arena.
The .htaccess entries I have added will redirect any URL on link.as or www.link.as to www.question-defense.com as displayed in the below example.
Initial link.as URL Below:
http://link.as/2010/02/04/vsftpd-error-gnutls-error-9-a-tls-packet-with-unexpected-length-was-received
Redirected In .htaccess To The www.question-defense.com URL Below:
http://www.question-defense.com/2010/02/04/vsftpd-error-gnutls-error-9-a-tls-packet-with-unexpected-length-was-received
As you can see the link will keep the exact same structure only switching the domain. Again if Google is crawling two different domains with the same exact content your SEO(Search Engine Optimization) score will be penalized thus meaning less traffic to your site. It is very important that you make sure to not point numerous domains to the same content without doing permanent redirects to this content.
Also worth mentioning is the fact that Pretty Link Pro is one of my favorite WordPress plugins to date. There is a free version of Pretty Link available here. If you like the plugin you can upgrade to Pretty Link Pro for $97 which is a steal considering all of the functionality provided. You can view more of the functionality on the Pretty Link Pro site. The plugin is the ultimate method to provide users a simple way share your WordPress site with others using Twitter, Facebook, Delicious, StumbleUpon, Mixx, Technorati, News Vine, LinkedIn, and Yahoo Bookmarks. The Pretty Link Pro WordPress plugin will also provide an easy method for you to automatically post a summary of your WordPress posts to Twitter by simply configuring your Twitter username and password within the Pretty Link interface. Other features including a link shortener not only for your posts but also a public version of the link Shortener for others to use which is another great method to draw awareness to your domain. Last but not least Pretty Link Pro will insert links automatically into your posts based on keywords which is an easy way to raise the amount of money you earn via advertising. If you run a WordPress site in any capacity I suggest checking out the Pretty Link Free Edition plugin at the very least to see what functionality is possible with this great plugin.
- Use htaccess To Redirect All Traffic To One Directory To A New URL Tonight we are launching a new portiong of Question-Defense.com called...
- .htaccess Redirect All Traffic to www There are a couple things that need to be considered...
- WordPress Default Redirect to WWW Not Working, Example from domain.com to www.domain.com I recently noticed that the redirect from question-defense.com to www.question-defense.com...
- Use GoDaddy.com DNS Services To Redirect A Sub Domain I recently developed a web site for a client on...
- Redirect https://domain.com to https://www.domain.com After purchasing a wildcard SSL certificate I was hoping to...
Tags: .htaccess, 3.0.1, delicious, domain, facebook, link, link shortener, link.as, linkedin, mixx, news vine, pretty link, pretty link pro, redirect, ReWriteCond, RewriteRule, StumbleUpon, technorati, twitter, URL, WordPress, www.question-defense.com, yahoo bookmarks


























Entries (RSS)
Great Article, thanks! However, the .htaccess script didn’t work for me until I added the line “RewriteEngine On” right under “”. Now that I added that line it seems to work.
Did you miss something there or are we running different servers?
Thanks!
[Reply]
alex Reply:
August 27th, 2010 at 12:28 PM
Hello Phillipp,
It should be the same regardless of the server type. I either forgot the “RewriteEngine on” line or it was turned on another way for me and I spaced adding it for this article. Thanks for pointing this out…. Did the data between your quotes above get cut off? Once you reply with what was in the quotes I will update the article for others and credit your comment above in a note. Thanks again for pointing this out.
Thanks.
alex
[Reply]