Search code examples
regexwordpress.htaccesshttp-redirectmod-alias

Whats wrong with my Redirect 301 Regex?


Google Search Console has some crawl errors and can't find these links:

home-third-blog-posts/page/10/
home-third-blog-posts/page/5/
home-third-blog-posts/page/7/
home-third-blog-posts/page/9/

And my Redirect rule in .htacces looks like this

Redirect 301 /\/home-third-blog-posts\/.*/s http://foo.com

My Regex-Tester says its correct but when i test the links the redirect doesn't work. What did i do wrong?


Solution

  • If you look at the documentation for Redirect directive, you'll see that it does not accept regex/patterns. You should be using the RedirectMatch instead:

    RedirectMatch 301 /home-third-blog-posts/.* http://foo.com
    

    also, no need to escape the / characters.