Join 3,572 readers in helping fund MetaFilter (Hide)

Tags:

301 Redirect Headache
November 22, 2010 3:16 PM   Subscribe

A weird 301 redirect request for a website.

I've done typical 301 redirects of files and directories.

However this new site was initially located at
www.randomdirectory.sitename.com

and is now located at sitename.com (with no www. at the beginning) is there a way to 301 redirect this so Google knows that it has moved?
posted by matimer to Technology (1 answer total)
 
This should do it - in the virtual host config (or adapted for .htaccess - I forget what if anything needs to change in that case, sorry)

This will get anything that's NOT starting with sitename.com and 301 redirect it with the full path intact to sitename.com


RewriteEngine On
RewriteCond %{HTTP_HOST} !^sitename\.com$ [NC]
RewriteRule ^(.*)$ http://sitename.com/$1 [R=301,L]


if you just want www removed, but have other domains left intact (like test.sitename.com, beta.sitename.com, etc) then change the RewriteCond to:
RewriteCond %{HTTP_HOST} ^www\.sitename\.com$ [NC]
posted by TravellingDen at 3:26 PM on November 22, 2010


« Older How bad is it, really, to have...   |  What are some tips for writing... Newer »
This thread is closed to new comments.