Faruk
Faruk

Reputation: 169

Rewrite rule and regex issue

I have Rewrite rule in web.config like this:

<rule name="Rewrite to page">
    <match url="^blog/([0-9]+)" />
    <action type="Rewrite" url="blog?page={R:1}" />
</rule>

So when you go to www.mysite.com/blog/1 it goes to 1st page of blog. For second page url is www.mysite.com/blog/2. But when I click on some blog from this pages it should redirect me to www.mysite.com/blog/2017/10/blog-post. Issue is with this Rewrite rule and regex, so it redirects me to www.mysite.com/blog/2017.

Any ideas?

Upvotes: 0

Views: 148

Answers (1)

C3roe
C3roe

Reputation: 96306

^blog/([0-9]+) matches too much here.

Add $ after the digits you are matching, so that they have to be the last thing in the requested URL - so that it does not match your individual post URLs any more.

Upvotes: 1

Related Questions