How to redirect with AND without trailing slashes

Topics: User Forum
Jan 11, 2013 at 4:06 PM


Could someone please help me with how do I redirect to the same page regardless whether the URL has trailing slash or not?


I would like both "" AND "" (notice the trailing slash) to redirect to the SAME page.

The trick is, first of all, that I have quite a few URLs that requires such redirects.

And second, there are URLs that are similar so the redirect needs to be able to distinguish between them. What I mean is, I had the problem, where I had "" redirect to one page, and "" redirect to a DIFFERENT page. Since part of the word "alien" can be found in both URLs, somehow the redirect found the first entry "" and immediately redirected there, without checking that I actually typed in "/alienated" so it should've redirected to that page. But instead, it just immediately found "/alien" and redirected there, skipping the other URL (where I wanted to go).

Currently I have the following redirect rules setup for each URL:

RedirectRule ^/alien$   [R=301]

With this, I seem to get different results with or without trailing slashes after "alien".


Thank you!

Jan 14, 2013 at 8:36 AM

If you make sure that your rules are in the right order , you should overcome the case where /alienated isn't picked up. I.e. make sure that your /alienated redirect is listed higher in your rule set.

To pick up on a url with and without a forward slash, just add /? to the end of your regular expression.

RedirectRule ^/alienated/?$   [R=301]
RedirectRule ^/alien/?$   [R=301]

The question mark means "0 or more", so will match whether it's there or not.


Jan 19, 2013 at 12:09 AM

Thanks for the reply shonk!

I added ^/alienated/*$ before I saw your post, which seemed to work as well.

Jan 21, 2013 at 8:31 AM

The rule as you've shown will always need to have a forward slash at the end, so consider the question mark, which makes it optional.

Your rule breaks down as follows:

Any string starting with a forward slash, followed by the word 'alienated', followed by a forward slash, followed by one single character only. I'm not sure that this will match what you're after effectively. I hope it does.