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 michele.me to michele.blog. 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 michele.me 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 michele.me server there's a mod_rewrite rule in Apache that is meant to catch any traffic destined for michele.me/blog and send it to michele.blog, while preserving the requested URL. eg. if the requested URL was http://www.michele.me/blog/archives/2016/12/working-preparing-new-house/ then it should pick up on the bit after /blog/ and send it over to the other server so that you land on https://michele.blog/working-preparing-new-house/
  2. On the michele.blog 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 http://www.michele.me/blog ie. the former "root" or "home" of this blog is being sent to the wrong place. Instead of it going to https://michele.blog it's ending up at https://michele.blog/blog-award-time/

The mod_rewrite rule in Apache is:

RewriteRule ^/blog/ https://michele.blog%{REQUEST_URI}

So while it'll pick up every other URL that was under michele.me/blog 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})/([^/]+)/$ https://michele.blog/$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 https://michele.blog/blog redirects to https://michele.blog/blog-award-time/ 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/?$ https://michele.blog [L]
    just before the line :
    RewriteRule ^/blog/ https://michele.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 michele.me/blog 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/?$ https://michele.blog [R=301,L]
    RewriteRule ^/blog/ https://michele.blog%{REQUEST_URI} [R=301,L]

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

  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