Best Way to Redirect Old Site/Domain to New Site/Domain?

Hi,
We’re developing a bunch of WordPress websites for clients, each with their own cPanel account on our VPS. Some have current websites and will keep their existing domain for the new site. We know to create 301 redirects for any pages that have a new directory structure compared to the old site’s (due to being a CMS now). We did find that in WordPress we couldn’t use the simple one line ‘Redirect 301 /old.html …’ code, but had to create more complex RewriteRules in the .htaccess file.

Here’s the code we had to use:


RewriteCond %{HTTP_HOST} ^domain.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.org$
RewriteRule ^home\\.html http://www.domain.org/ [R=301,L]
RewriteRule ^about\\.html http://www.domain.org/about-us/ [R=301,L]
etc....

But we also have clients who are changing their domains as well for the new sites. So their domains AND directory structure will be new. Maybe I’m overthinking it, but do you have to approach this a bit differently?

  1. We can usually park the old domain on the new account (in cPanel) and do a main redirect there. Does this only cover the root? What about subdirectories/files (in a check, those appear to NOT be redirected)?
  2. With the old domain parked on our new domain account, if we do need to create 301 redirects now for the altered page/directory structure, how would the above code need to be alterred?
  3. We’re assuming we do need to park the old domain on our new account or place the redirects on the old domain/site’s server, correct?!?

And in looking at an existing site with a cPanel parked domain, it looks like this was added to the .htaccess file automatically:


RewriteCond %{HTTP_HOST} ^domain\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.domain\\.com$
RewriteRule ^/?$ "http\\:\\/\\/www\\.domain\\.org\\/" [R=301,L]

Any help here would be greatly appreciated. THANKS!

I’m not an expert at this, but it sounds to me like you are making this a lot more complex than it needs to be. A domain name has to be hosted somewhere—whether at the company that hosts the website or elsewhere. If the site moves to a new server, you just need to redirect the domain to the new server by setting new name servers. That happens for the whole site. As soon as you do that, the old site is dead and gone. In the new site, you should be able to create a new .htaccess file in the root folder that redirects and old URLs to any new ones as you first described. (If I remember rightly, the WordPress .htaccess file is not in the root folder, so this may not cause conflicts, but I’d probably wait for someone more knowledgeable to confirm or deny that.)

(I’ve moved this thread to the Apache forum.)

Yeah, thanks. Sorry I didn’t see the proper forum category.

That works fine for clients keeping their old domains for their new sites, and what we have been doing so far.

I was more wondering about the differences when they are switching to a NEW domain at the same time, and how to properly redirect those old pages to retain SEO rankings and not have dead links. And they will most likely be canceling any old hosting accounts for their previous sites so as to not pay duplicate hosting fees. That’s why we offer to park the old domains.

Yes, to redirect from a disused domain to a new one, you have to keep the old one. Wherever that domain is hosted, you can normally set it to redirect to a new domain (via the domain host interface). As far as I know, that would just redirect any link to the old site to the home page of the new site, but I’m not sure. Perhaps another option would be to set up a hosting account on your server for the old site, and use a .htaccess file there to redirect pages from the old domain to pages on the new domain. I’m just thinking out loud, though. Hopefully there will be some better replies.

Any other insight here? We did a test on a site that has a separate domain parked on a root domain account in cPanel (using the Parked Domain feature), and redirected to the root domain (see code above for what that adds to the .htaccess file).

When we test the site, it appears that if we try the root URL of the parked domain, it does resolve to the main domain properly as you would hope. But if we try any other subdirectories/pages, these do NOT resolve to the root domain but instead keep the parked domain so that it ‘appears’ like a duplicate site (not good for SEO).

  • What needs to happen to properly redirect all pages/URLs of an old domain to a new domain when a new site is created??

Any old hosting will most likely be cancelled so there are not 2 hosting fees (old site/new site). So we would prefer to use our new site’s account (cPanel) to handle all domains and redirecting.

THANKS!

jd,

This IS overly complex as you’re dealing with different domains in separate accounts with the WP in either the DocumentRoot or a subdirectory. Then there’s the “developing for clients on your VPS” - are they being developed where they will be hosted? With this wild set of options (a multi-dimensional array), use of Redirect 301 statements would be ridiculous (use of mod_rewrite’s regex patterns could help but would not be likely to be worth the effort).

Okay, if you’re creating these CMS installations within subdomains/subdirectories of YOUR VPS, move the .htaccess code that WP writes to your DocumentRoot into the subdirectory and modify accordingly (look at the RewriteBase directive).


RewriteCond %{HTTP_HOST} ^domain.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.org$
RewriteRule ^home\\.html http://www.domain.org/ [R=301,L]
RewriteRule ^about\\.html http://www.domain.org/about-us/ [R=301,L]
etc....

I don’t understand what you’re trying to do. I assume that domain.org is the domain so one or the other RewriteCond will be matched so home.html will be redirected to the DocumentRoot.

Then about.html (ANY domain) will be redirected to the about-us subdirectory? Why “ANY domain”? If it’s for domain.org, too, you must repeat the RewriteCond statements.

Of course, if you don’t share the DocumentRoot with other domains, you don’t need the RewriteCond statements at all.


RewriteCond %{HTTP_HOST} ^domain\\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\\.domain\\.com$
RewriteRule ^/?$ [COLOR="#FF0000"]"[/COLOR]http[COLOR="#FF0000"]\\[/COLOR]:[COLOR="#FF0000"]\\[/COLOR]/[COLOR="#FF0000"]\\[/COLOR]/www\\.domain\\.org[COLOR="#FF0000"]\\[/COLOR]/" [R=301,L]

OMG! How horrid!

WP’s usual code is quite different than that as they use an <IfModule> wrapper (if you know you’ve enabled mod_rewrite, NEVER use the <IfModule> wrapper as it’s VERY ABUSIVE of the server), a RewriteBase / (which does nothing), an exclusion for index.php (which duplicates the !-f exclusion so this should be removed as useless) and requires at least one character in the {REQUEST_URI} before redirecting to index.php (better to use .? in case just the domain was requested and the DirectoryIndex was not modifified to include index.php). The best thing I can say about the stock WP mod_rewrite is that it comments its origin, tests for an existing file or directory before redirecting to its file handler.

Regards,

DK

Thanks for the reply, David. I’m trying to follow everything, but getting a bit lost in a couple places. I’ll re-read a couple times.

If it helps for clarification:

  • All sites will be in their own unique cPanel account on our VPS (which acts like a full server with root access). I’m pretty sure each cPanel account is pretty self-contained and separate from other cPanel accounts and the root (apart from any general server settings at the root).

  • All new sites are developed on their cPanel account where they will end up, but using a temporary domain so we can access things as we test. All indexing is disabled when in development. Domain is switched on cPanel account when time to go live (which requires some database edits) at which time indexing is enabled.

  • All sites are pretty straight forward WordPress installs, with no subdomains or ‘actual’ subdirectories per se. My mention of subdirectories was more referring to how the URLs ‘appear’ when SEF URLs are generated by WP.

  • All sites will be completely new and fresh. Any shared content will just be due to the client writing similar content to what they may have had prior. But it probably wouldn’t be exact, and most/all directory structure will probably be a bit different as well.

  • My question is about sites that will be using a new domain for their new site (they don’t like old one anymore). We understand how to handle using the same domain.

  • The first chunk of code above for the redirects is how we have to do it for a WordPress install when we are redirecting any indexed page URLs from an old site to appropriate pages on new site when using SAME domain name.

  • The second chunk of code is what cPanel writes to the .htaccess file when you park a domain and redirect it to the root domain.

Hope this clarifies things a bit. Didn’t think it would be so complex. I would imagine people do a ‘refresh’ occasionally when creating a new website, including a ‘better’ domain if available.

Thanks!

I still think it would be easier to set up a separate account on your VPS for each old site, and have that whole site redirected to the new site via an htaccess file in the root folder. May not be the most efficient solution, but it’s pretty easy, and it won’t really cost you anything. After a while, once Google has deleted links to the old sites, you could just remove the whole thing.

All new sites are developed on their cPanel account where they will end up, but using a temporary domain so we can access things as we test. All indexing is disabled when in development. Domain is switched on cPanel account when time to go live (which requires some database edits) at which time indexing is enabled.

Not sure how others do this, but I prefer to develop a new site in situ and just have a holding page (index.html) while the actual site has index.php. So it’s unlikley that anyone is going to find the new site before launch. Seems much easier to me.

I still think it would be easier to set up a separate account on your VPS for each old site, and have that whole site redirected to the new site via an htaccess file in the root folder.

That might work, but there’s just not enough in the budget for us to administrate that. We never know where a client’s site is hosted (sometimes they can’t even find out login info for us). And we already have 20-30 accounts on our VPS. If we started creating new accounts for each client that had an old domain, that could exponentially grow and become a drag to manage.

We’re hoping there is an easy-enough way to do it with a domain that is parked (or setup as an ‘Add-On Domain’) on a client’s new domain account.

It only takes a few minutes to set up and then you can leave it. All you need is access to their domain name, to redirect it to your own name servers. The cleint can ring their domain host to get the log in details if they’ve lost it. If you don’t have access to their domain, there’s nothing you can do to help them anyway.

What I’ve suggested may not be a very efficient way to proceed, I admit, but it’s easy, at least. :slight_smile:

jd,

If you got lost, it’s because I attacked my reply several times so I was very disjoint. My apologies.

  • All sites will be in their own unique cPanel account on our VPS (which acts like a full server with root access). I’m pretty sure each cPanel account is pretty self-contained and separate from other cPanel accounts and the root (apart from any general server settings at the root).

[indent][COLOR=“#0000FF”]They can only have their account on your VPS IF you have their domains pointed to your server.

Ralph’s suggestion is good BUT I’d use the domain name pointers and not a redirection at the old host as you cannot have one domain on two servers (so you’d have to use another domain name on your server which is not what you want to do).[/COLOR][/indent]

  • All new sites are developed on their cPanel account where they will end up, but using a temporary domain so we can access things as we test. All indexing is disabled when in development. Domain is switched on cPanel account when time to go live (which requires some database edits) at which time indexing is enabled.

[indent][COLOR=“#0000FF”]Ah, I should have read ahead, eh? It’s silly to register temporary domains, though, just for testing (unless they’re on your localhost as a test server - I didn’t get that impression, though). Even using YOUR main (or a test domain), you’d have to put these client domains in subdomains which would force modifications when you “go live” with the WP sites.

BTW, I use the same technique Ralph uses, i.e., changing the DirectoryIndex index.html index.php while in development (index.html would be a “work in progress” type of page allowing you to link directly to index.php to test the WP installation) then back to DirectoryIndex index.php index.html to “go live.”[/COLOR][/indent]

  • All sites are pretty straight forward WordPress installs, with no subdomains or ‘actual’ subdirectories per se. My mention of subdirectories was more referring to how the URLs ‘appear’ when SEF URLs are generated by WP.

  • All sites will be completely new and fresh. Any shared content will just be due to the client writing similar content to what they may have had prior. But it probably wouldn’t be exact, and most/all directory structure will probably be a bit different as well.

Ergo, no 301’s required.

  • My question is about sites that will be using a new domain for their new site (they don’t like old one anymore). We understand how to handle using the same domain.

Develop new domains as above (DirectoryIndex).

  • The first chunk of code above for the redirects is how we have to do it for a WordPress install when we are redirecting any indexed page URLs from an old site to appropriate pages on new site when using SAME domain name.

  • The second chunk of code is what cPanel writes to the .htaccess file when you park a domain and redirect it to the root domain.

Using WHICH .htaccess code? What you showed above wouldn’t do a thing (except preserve serving existing files). If you’re just changing .html files to extensionless files (or .php scripts) which are to be handled by WP, then strip the .html extension and they’ll get redirected to the index.php handler (where {THE_REQUEST} will be parsed for the requested content). Quite simple.

Hope this clarifies things a bit. Didn’t think it would be so complex. I would imagine people do a ‘refresh’ occasionally when creating a new website, including a ‘better’ domain if available.

I think it was the lack of specificity the first time. Right now, it seems to be pretty simple (like Ralph first said - he probably interpreted your original post correctly).

Ralph,

No, the comment above about domains applies. What you’re describing is a test domain using, well, a subdomain of jd’s test domain and that would be awkward to install, run and then update when the testing is completed. However, you were spot on with the DirectoryIndex solution you offered! :tup:

The beauty of using the registrar’s pointers is that jd’s clients never have to provide the logins to their hosting accounts, just the registrars.

Regards,

DK

That’s not really what I meant. jd mentioned that some client sites, along with their domains, were going to be scrapped, and was asking how to redirect Google links from the old (abandoned) sites to the new sites with their new domains. (That’s how I understand it, anyhow.) I was saying that one option is to set up a CPanel account on his own server for each old site and, in each case, redirect the old domain to that (thus keep the old domain alive but dump the old hosting account). Then, in each case, he could use a .htaccess file on his own server for fine-grained redirection of all the deleted pages from the old site, redirecting them to new pages on the new site. Maybe it’s a silly idea … I’m not sure. But the alternative seemed to be just to keep the domain name and not have an associated hosting account—in which case (as I understand) there would only be the option to redirect anything from the old domain to the domain of the new site without the choice of specific pages … meaning that all old links in Google would presumably just land on the home page of the new site. If domain hosts offer more fine-grained redirection than that, I’d be interested.

I’ve not yet built a dynamic site (using a CMS) anywhere but in its final location. I’m not very confident with moving a whole DB site to a new domain. I hope to learn how to do it, as sometimes it’s unavoidable, but I’ve managed to avoid it so far. :slight_smile:

Hi Ralph!

Whew! I knew you were smarter than that!

Right! Re-point the domains to the VPS which will handle the DNS records on the server (for each domain).

Keeping the PR is easy IF you can redirect the old links. Normally, that’s a difficult thing (RewriteMap) because “webmasters” don’t plan ahead and maintain the same filename (sans extension - which would make the redirection trivial because regular expressions could match the pattern and make the redirections). It’s not a silly idea at all but PPPPPPP (proper prior planning prevents piss poor performance) is essential (and rarely applied).

What I was “going off” about was redirecting from the domain on the old host to the domain on the new host - it can’t be done! The registrar can only point to one DNS (pair) per domain. You could create a subdomain of another domain on the new host but that would result in reconfiguration tasks when going live. In other words, your first inclination (as above) was the correct and proper one for jd to use.

You just have to live long enough to have to move a CMS from one host/domain to another. :smiley:

Regards,

DK

jd mentioned that some client sites, along with their domains, were going to be scrapped, and was asking how to redirect Google links from the old (abandoned) sites to the new sites with their new domains. (That’s how I understand it, anyhow.) I was saying that one option is to set up a CPanel account on his own server for each old site and, in each case, redirect the old domain to that (thus keep the old domain alive but dump the old hosting account). Then, in each case, he could use a .htaccess file on his own server for fine-grained redirection of all the deleted pages from the old site, redirecting them to new pages on the new site.

Yes, sorry for any confusion. That’s what we’re trying to do (redirect old pages on old domain to their new counterparts so no broken links). And we’re not talking hundreds of unique pages, more like dozens if that. We can even just do the most important pages. We will (obviously) need to have access to their registrar so we can point the old domain to our server. We’ve always known that.

- So I guess the main issue still is/was, can we do the redirecting from ONE cPanel account and it’s .htaccess file?
This cPanel account would have the NEW domain as it’s root account, but have the old domain parked on it. This would just be a lot simpler to manage. I guess we just need to understand what’s technically happening when the old domain is ‘parked’ in cPanel.

We’ll post something in the cPanel forums as well about this, but it’s just not as responsive.

And thanks for the insight on test/dev site setup. We’re fine with what we’re doing here. We have one main test domain (e.g., testsites.com) and just use a subdomain of that for each new cPanel account when the client is keeping their existing domain but has an old site that we obviously can’t disable until the new site is ready to go live. For NEW domains, however, we could use the DirectoryIndex idea you mentioned if we thought it was necessary.

THANKS AGAIN FOR THE HELP!

jd,

The confusion was probably on my part so I should be apologizing to you.

Maintaining PR is an important task so, as I intimated above, you MUST do your planning to make the task easier for yourself, i.e., use the same name for the new page’s link (at least some pattern that you can match from the old website to the new).

Failing to do so will force you into a RewriteMap situation which requires tweaking of the server’s config file (RewriteMap cannot be established via .htaccess). Whether you choose to use a simple map (similar to the text maps used as an example at Apache.org, i.e., Mr.Joe.Average joe # Mr. Average) or a program to access a database, it can bring a server down so RewriteMaps can only be created by the server or vhost configuration files.

Main issue: From one cPanel account, you can use a single .htaccess file provided the old domain is parked on top of the new domain. mod_rewrite code in .htaccess will have to go through the RewriteCond %{HTTP_HOST} old\.domain [NC] tests for EVERY RewriteRule (unless you use the Switch flag - see the tutorial linked in my signature) but it can handle multiple, co-located domains. Do you really call that “simpler?” :smiley:

“… what is happening with a parked domain” is that ALL FILES ARE SHARED and available to each domain. The only drawback, if it can be considered to be one, is that you can’t have duplicate file names used by the multiple domains. Okay, you can but the distinction must be drawn within the script and separate code provided for each. (Yes, I do that for one of my domain/parked doppelganger so I can confirm that it works a treat.)

My test setup (localhost) merely uses the TLD-less domain name (example vs example.com) OR an abbreviation thereof (ex?). That makes domain-specific code easy to test and beats the heck out of using subdomains (IMHO). With a large team, though, the subdomains accessible via the Internet may provide the advantages I don’t need.

You’re very welcome!

Regards,

DK