Redirect question, with a sweet twist.
March 3, 2009 10:13 PM   RSS feed for this thread Subscribe

I'm moving Wordpress from www.mydomain.com to www.mydomain.com/blog, but I'm also putting in something new at root that I want people to see. Please .htaccess my brains out.

I would like to move my Wordpress installation from www.mydomain.com to www.mydomain.com/blog, so I can put a sweet Sweetcron installation at root. After I move Wordpress, I want to make sure that all my pages map to their new URLS. For example, http://www.mydomain.com/2009/03/03/sample-post/ needs to go to http://www.mydomain.com/blog/2009/03/03/sample-post/

But! Since I'll have a new page at root, I do not want www.mydomain.com to redirect to www.mydomain.com/blog. I want people who land at www.mydomain.com/index.php to stay right where they are. I've tried tutorials, video tutorials, and htaccess generators, but nothing seems to work. This question doesn't cover it either. I know there's a combination of rules out there for me. Thanks in advance.
posted by miniminimarket to computers & internet (9 comments total) 5 users marked this as a favorite
RewriteEngine on
RewriteRule ^200(.*)$ /blog/200$1 [r=301,nc]

to the rescue!
posted by soma lkzx at 10:18 PM on March 3


or RewriteRule ^20(.*)$ /blog/20$1 [r=301,nc] if you're still going to be blogging in the incredible future that is 2010.
posted by soma lkzx at 10:19 PM on March 3


Your redirects need to guess whether a given request is for wp or for something else, right? I'd use a RedirectMatch (or a mod_rewrite rule) and redirect all urls that look wordpress-y (say, which start with four digits— I'm not sure what other urls wp might want to serve up. You could grep your access logs to see, I guess.) You need to leave alone any urls that sweetcron should respond to, of course.
posted by hattifattener at 10:20 PM on March 3


Cool, soma lkzx -- so that would take care of all my 200- posts? I do have some pages on my www.mydomain.com Wordpress install, like www.mydomain.com/about-me/ but those aren't that important. I'm still not entirely sure about rewrite vs redirect, but I think rewrite is the better choice, Google/SEO-wise..? Thanks again.
posted by miniminimarket at 10:30 PM on March 3


For the rest you can do something like

Redirect 301 /about-me/ http://www.mydomain.com/blog/about-me/

on a per-page basis. As for the difference, RewriteRules are dynamic and magic redirects, while 'Redirect' is just "here's one page, here's the new page". Don't worry, though, the r=301 in the RewriteRule is sending a 301 redirect to Google, so your SEO is just fine.
posted by soma lkzx at 10:35 PM on March 3


Rewrite will make the blog pages appear at the old URL (it's "rewriting" the incoming request before Apache decides how to deal with it); redirect will mean that browsers visiting the old URL will get redirected to the new URL.
posted by hattifattener at 11:29 PM on March 3


hattifattner: actually, no. the "r" in "[r=301,nc]" means "redirect". The 301 means "moved permanently" and the "nc" means "no case" ie. be case insensitive. The end result of soma's directive is a redirect.
posted by beerbajay at 3:12 AM on March 4


soma lkzx: This totally worked. For anyone else moving their Wordpress installation, don't forget that you might also have to move tags and categories over, but that's much simpler:

redirect 301 /tag http://mydomain.com/blog/tag

etc etc.

Now I just need to regenerate a new Google sitemap and change my Feedburner feed. Hopefully that handles everything I needed for the transition.
posted by miniminimarket at 8:35 AM on March 4


beerbajay: Ah, you're right, of course. I usually use mod_rewrite to rewrite without emitting a redirect.
posted by hattifattener at 11:15 PM on March 4


« Older I want to do volunteer project...   |   If you have smoked two or more... Newer »

You are not logged in, either login or create an account to post comments