2

I recently switched my blog from wordpress to ghost. In order to keep the old wordpress urls working, I added some rewrite rules.

My wordpress site used the following url formats:

  • /blog/year/month/post-title
  • /blog/index.php/year/month/post-title

Ghost uses the following url format:

  • /post-title

Here's my main rewrite rule. It works fine for the pattern without index.php, but with index.php, it redirects to /index/.

<rule name="wordpress to ghost" stopProcessing="true">
    <match url="^blog/(index\.php/)?\d+/\d+/([\w\-]+)/?" />
    <action type="Redirect" url="{R:2}" />
</rule>

How can I fix this rule to correctly redirect urls with index.php?

1
  • Have been able to give the escaped regex pattern in my answer below a test yet?
    – Ryan Joy
    Sep 13, 2015 at 18:38

1 Answer 1

3
+250

I've tested this with my own installed instance of Ghost on Azure, but I'm not getting the redirect you are. {R:2} correctly returns the second grouping (slug name).

However, I do notice that you are not escaping your forward slashes. Try the following:

    <rule name="wordpress to ghost" stopProcessing="true">
        <match url="^blog\/(index\.php\/)?\d+\/\d+\/([\w\-]+)\/?" />
        <action type="Redirect" url="{R:2}" redirectType="Permanent" />
    </rule>
1
  • 1
    That worked! But I'm still curious why it worked for links without index.php without escaping forward slashes.
    – jrummell
    Sep 14, 2015 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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