RedirectMatch example.com/post-slug to example.com/post/post-slug

I have built a custom WordPress theme that displays posts in a modal from the home page.

I need to redirect from

Read More
http://example.com/my-post-slug

to

http://example.com/post/my-post-slug

I’ve tried to figure out RedirectMatch but with no luck. So far I tried this but it just causes an infinite loop:

RedirectMatch 301 ^/(.*)$ /post/$1

Any help would be appreciated.

Related posts

1 comment

  1. You can use this tweaked regex in the rule:

    RedirectMatch 301 ^/([^/.]+)$ /post/$1
    

    [^/]+ will not match /post/somepost hence will not cause any redirect loop. Make sure to clear your browser cache.

Comments are closed.