I have a wordpress site that's approximately 25% "business" pages and 75% "techie" pages. The current site: mysite.com, I'm splitting into two separate domains: mysite.com for the business stuff and tech.mysite.com for the tech stuff.

I'm looking for recommendations on how to best go about rewriting all the existing "techie" URLs to point to the new "tech.mysite.com" domain instead of their current "mysite.com". I wouldn't be changing anything except putting the tech subdomain at the front.

Options, as far as I'm aware:

Rewriting via htaccess I'd prefer not to do this, mostly because of the number of pages (~50) and don't want the upfront overhead of having to check all the rewrite rules here before anything else is done. Maybe I'm over-concerned.

Some Wordpress Plugin Not a fan of this option either: I don't trust pick your plugin to be able to get it right, without a performance hit.

PHP code I'm thinking this is probably the way to go... if the original page is gone, it'd redirect to the error page, at which point I can put in a global hook that would check for the original request URL and redirect to the new one accordingly. This seems good because a) I can have a central place to manage all cases (including upcoming/future cases), and b) the overhead of matching URLs isn't invoked until an original page is **not* found.

Has anyone done this before, and can offer some pointers on the best way to go about it?

  • What criteria will you use to choose which one? Nov 28 '15 at 0:12
  • Which URLs? Manual list/database I suppose. Which method? Performant and mantainable.
    – jdl134679
    Nov 28 '15 at 0:24
  • 2
    Everyone says that. "Performant and maintainable." How will you choose? Until you know how you're going to make the choice, you won't be able to make the choice, and polling random strangers on the internet is not going to help. Nov 28 '15 at 0:41
  • What is "best" depends on your knowledge and your local serer setting and other requirements. As it is it is just too broad or just opinion based. Nov 28 '15 at 4:14
  • If you are going to make 301 redirections, do it with .htaccess if possible; this way, no single line of PHP is executed and you don't waste server resources. Here is the performant part. Also, you can write one or very few rewrite rules that can handle unlimited number of redirections; here is the mantainable part. But without more information, it just a opinion.
    – cybmeta
    Nov 30 '15 at 15:13

I think htaccess would be fastest way. Overhead of checking 50 simple regexp is very small - page generation is several orders of magnitude slower so you shouldn't care about it. This wont hit performance, you can set rewrite only for domain mysite.com and it won't check rules for tech.mysite.com reducing overhead, which isn't noticeable anyway.

The disadvantage of modifying wordpress code is that you modification may break with wordpress update and you should remember about it every time you're updating it.

If you want to make your site faster then try nginx webserver. It can work with php-fpm without apache, or just serve static files much more effectively than apache and proxy requests to php to apache. There is also similar webserver lighthttp.

  • Thanks... I wasn't sure how performance would be. I can probably get away with regex for perhaps 50% of what needs to be migrated, but there'd still be a number of individual lines that'd have to go in there as well. The point about customizing the PHP is a good one that I hadn't considered. Site speed is currently excellent, just trying to be proactive about keeping it that way.
    – jleach
    Nov 28 '15 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.