Forum Topic: Redirecting for slashes and without slashes

Forum: .htaccess Forum : Redirecting • Posted by Yael Miller • Updated:

Let's say I had a page named pancakes on my site but I've deleted it and want to redirect to my home page. I want to make sure that people who have entered /pancakes/ and /pancakes will be redirected.

Previously, I've done the below:

Redirect 301 /pancakes/
Redirect 301 /pancakes

Now I want to have one line instead of two. Which of the below rules is the correct one?

RedirectMatch 301 /pancakes/?$
RedirectMatch 301 /pancakes(.*)

2 Replies to “Redirecting for slashes and without slashes”

Jeff Starr
Posted by Jeff Starr

It depends on which case you're after:

/pancakes/?$ will match only the following URLs:

On the other hand, /pancakes(.*) matches much more, such as:

So it depends, basically, on whether you're also redirecting any sub-content.

Posted by Yael Miller •

Thanks for explaining.