Mod_Rewrite Help Needed!!

It's only fair to share...Share on Facebook9Share on Google+0Tweet about this on Twitter0Share on LinkedIn0

frustrated and exhausted man

As I mentioned yesterday I switched this blog over from to And a BIG thanks is owed to Don and Paolo from the .blog team for helping me get that domain in the first place!

The domain will be used for "other things" in the future, so I am splitting the blog away from the rest of the site.

As part of the switch I've also changed the WordPress permalink structure over to the shorter or more direct /%postname%/ using Yoast's handy little tool to generate the necessary rule.

In order to do that "sanely", while also trying not to lose any web traffic I've got two sets of redirects setup:

  1. Over on the server there's a mod_rewrite rule in Apache that is meant to catch any traffic destined for and send it to, while preserving the requested URL. eg. if the requested URL was then it should pick up on the bit after /blog/ and send it over to the other server so that you land on
  2. On the server there's a mod_rewrite rule in the .htaccess that will map the old permalinks to the new and shorter one (the example above shows how stupidly long the paths were previously). It'll transform the old (and super long) URL to the shorter permalink structure.

Everything is *almost* working, but there are a few stupid problems that I can't seem to fix, though I know they should be fixable via mod_rewrite.

At the moment *any* traffic hitting ie. the former "root" or "home" of this blog is being sent to the wrong place. Instead of it going to it's ending up at

The mod_rewrite rule in Apache is:

RewriteRule ^/blog/{REQUEST_URI}

So while it'll pick up every other URL that was under it's not handling the "root" link properly at all.

On this server there's a mod_rewrite rule that is handling the mapping to specific posts, pages etc.,:

RedirectMatch 301 ^/blog/archives/([0-9]{4})/([0-9]{2})/([^/]+)/$$3

I'm not sure which of the two rewrite rules is missing something, but I suspect it's the first one.

So if there are any Apache mod_rewrite gurus out there who have any idea on how to fix this before I lose my mind I'd love to hear from you!


It's only fair to share...Share on Facebook9Share on Google+0Tweet about this on Twitter0Share on LinkedIn0

Related Posts:

, , , ,

5 Responses to Mod_Rewrite Help Needed!!

  1. dr1ss January 13, 2017 at 9:25 am #

    mod_rewrite can be fun at times 🙂
    After a quick check, your issue doesn’t concern your old domain. The redirection is fine, what you should investigate is why redirects to because that’s where people from your old domain get redirected to.
    As a “quick and dirty” fix in mean time what you can do is add this line on your old htaccess :
    RewriteRule ^/blog/?$ [L]
    just before the line :
    RewriteRule ^/blog/{REQUEST_URI}
    this should redirect the old homepage straight to to your new address.

  2. Michele Neylon January 13, 2017 at 10:54 am #

    Thanks, but when I try that I can’t get to load at all 🙁

  3. dr1ss January 13, 2017 at 10:59 am #

    Would be great if you could share the whole htaccess to better identify the issue

  4. Michele Neylon January 13, 2017 at 11:09 am #

    @dr1ss – Stephen managed to fix it – so the new rule is:
    RewriteRule ^/blog/?$ [R=301,L]
    RewriteRule ^/blog/{REQUEST_URI} [R=301,L]

    Thanks – you pointed him in the right direction and it all seems to be working properly now 🙂

  5. dr1ss January 13, 2017 at 11:11 am #

    Yeah the second rule needed the [L] probably because u had other rules after (that why I asked to see the htaccess hehe)
    Glad everything is working as you want

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Powered by WordPress. Designed by WooThemes