Home Trailing slash redirects to root
Reply: 1

Trailing slash redirects to root

Arrisar
1#
Arrisar Published in 2018-02-07 05:20:42Z

I've built a new WordPress blog for the company I work for and am having trouble implementing a catch-all redirect for the new permalink structure.

The old URL structure looked like:

https://blog.company.com/blog/2018/02/07/what-a-cool-post/

With the new structure like:

https://blog.company.com/what-a-cool-post/

The trouble lies in the the trailing slash on the first post. If I remove the slash, then the redirect works as intended, but if you leave the slash in the URL, it redirects to the root.

https://blog.company.com/blog/2018/02/07/what-a-cool-post/ => https://blog.company.com/

https://blog.company.com/blog/2018/02/07/what-a-cool-post => https://blog.company.com/what-a-cool-post/

The redirect rules are below (and appear before all others):

RedirectMatch 301 ^blog/([0-9]){4}/([0-9]){2}/([0-9]){2}/(.*)$ https://blog.company.com/$1

How should this rule be set up?

Arrisar
2#
Arrisar Reply to 2018-02-07 06:23:55Z

After much help from another employee, we were able to resolve this. The error appears to have been from not including the opening slash.

We rewrote the rule as such (including cleaner regex and removed excess capture groups):

RedirectMatch 301 ^/blog/\d{4}/\d{2}/\d{2}/(.*)$ https://blog.company.com/$1

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.427233 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO