301 Redirect vs 301 RedirectMatch

I was recently tasked with redirecting a url, pretty straightforward I thought.

I said that was easy. But the issue was the trailing slash – this character had to be optional.

In your .htaccess file…


Redirect 301 /page-1/ /page-2/

Introducing RedirectMatch. With RedirectMatch, we can utilize regular expressions to capture a trailing slash or non-trailing slash scenario.


RedirectMatch 301 (?i)/page/?$ https://site.com/page/

The question mark “?” here means, “hey I’m optional”. In this case, the url can be both case insensitive followed by a trailing slash (or a non trailing slash).