How to add Apache 301 redirect to VirtualHost in Apache

I’ve had two domain names which were pointing to the same website content.
As one can read in any SEO guide around this is a really bad practice as search engines things automatically there is a duplicate site content and this has automatically a negative effect on the site pagerank.
To deal with situation where multiple domains are pointing to the same websites its suggested by many SEO specialists that a 301 redirect is created from all the domain websites to a single website domain which will open the actual website.

Making the 301 direct domain from the sample domain my-redirect-domain.com to www.mydomain.com can be done with a virtualhost dfefinition in either httpd.conf or with the respective file containing the domain virtualhost definitions:
Here is the exact VirtualHost code I use to make a 301 redirect.

<VirtualHost *>  ServerAdmin support@mydomain.com  ServerName my-redirected-domain.com
ServerAlias my-redirected-domain.com www.my-redirected-domain.com
RewriteEngine on RewriteRule ^/(.*) http://www.mydomain.com/$1 [L,R=301]
</VirtualHost>

After placing the VirtualHost redirect, an apache redirect is required.
Further on when a Gooogle or Yahoo Bot visits the website and does any request to my-redirect-domain.com or www.my-redirect-domain.com , they will be redirected with a 301 reuturned code to www.mydomain.com

This kind of redirect however can have a negative impact on the Apache CPU use (performance), especially if the my-redirect-domain.com is high traffic domain. This is because the redirect is done with mod_rewrite.

Therefore it might be better on high traffic domains to create the mod_rewrite redirect by using a vhost like:

<VirtualHost *>
ServerAdmin support@mydomain.com
ServerName my-redirected-domain.com
Redirect 301 / http://www.mydomain.com/
</VirtualHost>

The downside of using the Apache 301 redirect capabilities like in the above example is that any passed domain urls like let’s say http://www.my-redirected-domain.com/support/ would not be 301 redirected to http://www.mydomain.com/support/ but instead the redirect will be done straight to http://www.mydomain.com/

Share this on:

More helpful Articles

Download PDFDownload PDF

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

5 Responses to “How to add Apache 301 redirect to VirtualHost in Apache”

  1. Thibs says:
    Firefox 6.0.2 Firefox 6.0.2 Windows XP Windows XP
    Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2

    Hello,

    I think we can do the same with such definition

    ServerAdmin support@mydomain.com
    ServerName my-redirected-domain.com
    Redirect permanent / / http://www.mydomain.com/

    View CommentView Comment
  2. Marta Wormley says:
    Opera 9.64 Opera 9.64 Windows XP Windows XP
    Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1

    We think your information is useful and will revisit for an update in the future.
    We also have an information source that is useful and if we can find any synergy in our aims it would be great.We love any details on anything related to Stumbleupon

    View CommentView Comment
  3. Gilberto Lawas says:
    Firefox 11.0 Firefox 11.0 Ubuntu Ubuntu
    Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:11.0) Gecko/20100101 Firefox/11.0

    Thank You.

    View CommentView Comment
  4. alessandro says:
    Safari 6.0.2 Safari 6.0.2 Mac OS X  10.8.2 Mac OS X 10.8.2
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17

    With apache 2.x, the

    Redirect 301 / it.bestshopping.com/

    must be written

    Redirect permanent / it.bestshopping.com/

    to achieve an httpd 301 Moved Permanently request.

    View CommentView Comment
  5. Greta says:
    Google Chrome 28.0.1500.71 Google Chrome 28.0.1500.71 Windows 7 Windows 7
    Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36

    Hey! Someone in my Facebook group shared this site with us so I came
    to give it a look. I’m definitely loving the information.
    I’m bookmarking and will be tweeting this to my followers!
    Exceptional blog and amazing design.

    View CommentView Comment

Leave a Reply

CommentLuv badge