PDA

View Full Version : htaccess help with domain change


beastnatch
11-29-2009, 07:53 AM
So I'm working with someone who change their domain from something like example.com to example.forumexample.com. I'm having him test the following code in the .htaccess file.

RewriteEngine On
rewritecond %{http_host} ^example.com
rewriteRule ^(.*) http://example.forumexample.com/$1 [R=301,L]

On my personal website I use that to just add the http://www to my webpages, but figured the same code could accomplish this. As soon as he gets back to me I'll verify that it even worked.

What the goal is, is to use example.com as a homepage containing the link to the new site. I want all the old links to be useable through google (and elsewhere) and not ding him for changing his domain (as they are not hosted at the old domain any longer). I think that will work. This was my bandaid for the problem with google links and such, but I would like however for the actual homepage to not forward to the new domain. Just everything else. Is there a way to create an exception in .htaccess to allow that one page to work without the forward?
Thanks

beastnatch
12-02-2009, 11:02 PM
Well in case anyone cares, I figured out a solution. Here's what I did.

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - []

RewriteRule ^(thread[^/]*)$ http://example.forumdomain.com/$1 []
RewriteRule ^(thread/[^/]*)$ http://example.forumdomain.com/$1 []


I removed the [L] tags and it now looks at all the code in my file. Does anyone know if there are any pro's or con's to adding the [R=301] tag to a redirect? Would it be good or bad to add it more than once in a .htaccess file? Any SEO pro's or con's to it?

Thanks!

sybil6
12-19-2009, 10:56 AM
301 permanent is what i use when i have to switch files and want to keep my keywords rank on google and it's what google recommends.