Thursday, January 22, 2009

301 Permenant Redirects in Apache on CentOS

Hello and welcome back to 301 Redirects and you.  You might remember that I did a post on 301 Redirects on IIS a few years ago, way back in 2007 actually.

Today we are concerned with the Apache web server and doing SEO / SSL friendly 301 redirects for host.com to www.host.com.

If you are just running host.com and not using any named virtual hosts you can do:
ServerName www.host.com
RewriteEngine on
RewriteRule ^/(.*) http://www.host.com/$1 [L,R=301]

If you are running named virtual hosts you can then add the directives below to your virtual hosts.

<VirtualHost *:80>
       ServerName somehost.com
       Redirect 301 / http://host.com
</VirtualHost>

No comments: