|
How do I add a 301 redirect to my Apache httpd.conf?I just checked and apparently both the "domain.com" and "www.domain.com" work for my site, bringing up the same page with different URLs. According to an SEO buddy of mine, that's a bad thing. Is it? And if so, how can I tweak my web server configuration to fix it? This is a bad thing, as your friend suggests. The reason? Every URL is considered as a different page on your site according to the search engines, so while you might deserve, say, a combined PageRank on Google of five, it might be that "hostname.com" is a PR3 and "www.hostname.com" is a PR4 when you check. You can quickly ascertain whether your site has this problem too, by simply entering in both versions of the domain name to your Web browser and checking to see if they stay as you typed them in (bad) or one of them is magically rewritten to be in the other form so that there's a single, consistent URL for both (good). If you need to tweak this, as I had to on this site recently, you can most easily do so by going into your httpd.conf file and adding the following three lines: <VirtualHost askdavetaylor.com>
Redirect 301 / http://www.askdavetaylor.com/ </VirtualHost> In this instance, I want the form "www.askdavetaylor.com" as the default consolidated domain name format. You can test it: click on this link and watch what URL you actually have in your Web browser by the time you get the home page: http://askdavetaylor.com/. Depending on your Apache configuration, you might need a more sophisticated version of this too: <VirtualHost 70.84.11.36> ServerName askdavetaylor.com
RewriteEngine on RewriteRule ^/(.*) http://www.askdavetaylor.com/$1 [L,R=301] </VirtualHost> The difference between the two is that the latter only works if this is the only domain that is assigned the specified IP address, while the former works if you have multiple domains with the same IP address, as I do on my own server. Also note that while the Apache Rewrite Engine is darn cool and very powerful (I use it for lots of tricks on this site) it's also slow, so engaging it when you don't really need to use it can slow down your Web server. Not a good thing. Finally, it's important that you use a 301 permanent redirect rather than 302 temporary redirects so as not to get into trouble with Google and other search engines. Google's Matt Cutts has a worthwhile article on this subject if you want to know why this is so: The little 301 that could. If you want to know more about redirects and error pages, by the way, you might well find the site custom 404 error page amusing and useful. Thanks to Steve Loyola of Best Book Buys.com and Alek Komarnitsky, who is busy trying to raise money for charity through the weird and wacky V7ndotcom elursrebmem competition, for their assistance with this important server note.
Categorized:
CGI Scripts and Web Site Programming
(Article 6375,
Written by Dave Taylor)
Tagged: 301 redirect, apache, httpd.conf Previous: Can I use incredimail along with Google's Gmail? Next: How do I set up a wireless wifi access point for my Sony PSP? Subscribe!
Nice writeup Dave and great explanation of a technical topic that is useful for webmasters. BTW, I know that Alek guy and he can be pretty wierd and wacky ... he's always up to something entertaining! ;-) Posted by: Mr. Christmas Lights at March 19, 2006 5:46 PMThanks for the information. Can you also mention how to set this redirection up on IIS for those of us paying for hosting with companies that don't use Apache? Posted by: physio at March 20, 2006 9:16 AMPhysio, that's documented at the http://www.404-error-page.com/ site. Check it out! Posted by: Dave Taylor at March 20, 2006 9:38 AMDave, thanks for your very informative information on yourdomain.com to www.yourdomain.com 301 redirects through modifications to the httpd.conf file. I tested your approach on my server and it works exactly as advertised. Are you using "former" and "latter" correctly? Former would be: Redirect 301 / http://www.askdavetaylor.com/ You say "the former works if you have multiple domains with the same IP address" I think you've got it reversed. Posted by: Erik at February 5, 2007 1:52 PMJust a warning! A cut and paste of Dave Taylor's second bit of code will actually redirect your website to www.askdavetaylor.com :) Yeah, I know that's obvious. But trust me, it's a bit startling to see type in your domain name and end up at dave's website :). D'Oh! Posted by: Glenn at April 8, 2008 6:51 PMWow, such simple instructions, and it worked first time. Many thanks Dave, I owe you a cuppa! P.S. to check the http headers use: http://www.seoconsultants.com/tools/headers.asp#Results Posted by: Suresh at September 29, 2009 9:35 AMI have found your solution for multiple domains on one IP not working on apache 2.2.11. The virtual hosts overlap each other and some are ignored. Instead, I have created one virtual host per redirect target as follow: VirtualHost *:80 VirtualHost *:80 Add the <> around the Virtualhost lines, for some reason it was removed from the comment Posted by: Jean-Michel Raux at November 25, 2009 1:39 PMWhen I use the first method Redirect 301 / http://www.askdavetaylor.com/ Second method doesn't redirect my site at all. Here is the httpd.conf file: Order allow,deny RewriteEngine on SecFilterEngine Off
ExpiresActive On ExpiresDefault A29030400 ExpiresDefault A1209600 ExpiresDefault A604800 ExpiresActive Off ***your website comment area automatically removes some characters so tags are gone. Posted by: Jeremy at December 20, 2011 12:19 PMI have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |