Proper htaccess structure for redirecting an entire site?

  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 01, 2007
  • Posts: 315
  • Status: Offline

Post July 30th, 2009, 8:55 am

I am moving a site to a new domain soon and would like to do a 301 redirect to maintain SEO quality backlinks. The URL structures on the new domain will be exactly like the old with a different domain name. This site has close to a thousand or so pages so I am not really interested in writing a new line for each page and permalink in the htaccess. Is there a simple REGEX command that I can use that will cover all the possible pages and permalinks?
Joe Hall
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 30th, 2009, 8:55 am

  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 01, 2007
  • Posts: 315
  • Status: Offline

Post July 30th, 2009, 8:58 am

I did a bit more research and came across this

Code: [ Select ]
Rewriterule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]


Will this work? I don't really have anyway to test this..its kinda like I have to get it right the first time!
Joe Hall
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post July 30th, 2009, 9:42 am

It can work, as long as there are no conflicting rewrites higher up in the processing than that one. Once the new server is in place there is really no reason to have the existing server processing any mod_rewrite directives other than that one and possible a RewriteEngine On rule.

If you decide to add a GET variable to the destination URL to track redirects, be sure to use the QSA flag along with that R=301 flag.
Strong with this one, the sudo is.
  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 01, 2007
  • Posts: 315
  • Status: Offline

Post July 30th, 2009, 9:48 am

Ok cool, i just realized though that I actually need to do this on 2 sites. The second one i need to redirect at a directory level. In other words, I want to redirect oldsite.com/blog/ to newsite.com/blog/ and keep the content in the root of oldsite.com/ where it is. Would the redirect for that look like this?

Code: [ Select ]
Rewriterule ^blog/(.*)$ http://www.newsite.com/blog/$1 [R=301,L]
Joe Hall
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post July 30th, 2009, 10:18 am

So on the second site, you'll be keeping the majority of the site where it is, but the /blog/ directory will be moving to a new domain ?

Leave a /blog/ directory intact on the existing site with an htaccess in it and do the redirect from within that directory. Doing it this way keeps the server from needing to worry about the blog redirect during every single request and lets it just worry about it when the request gets to that /blog/ directory.

/blog/.htaccess

Code: [ Select ]
Rewriterule ^(.*)$ http://www.newdomain.com/blog/$1 [R=301,L]


When RewriteRule is used in the htaccess of sub-directories, the names of parent directories are not included in the URI mod_rewrite will be working with.

Now when you test this on your server in an unused directory before going live, if it starts adding what looks like physical file paths to your URLs, you'll want to use RewriteBase to let mod_rewrite know where you are.
Strong with this one, the sudo is.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: Kurthead+1 and 137 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.