I'm hoping someone that's better than I at RewriteRule can help.
I have a site that seems to have a bad link coming in from somewhere at Amazon. I keep seeing page not found errors like:

page/my-books/\
page/my-books/\/\

as well as others like these, all ending in either /\ or /\/\ . I tried several rewriterule's but none seemed to work. I just want to have it get rid of the extra /\ and redirect it to the correct pages, like page/my-books, in this example. This is just until I can find where the bad link is coming in from.

Comments

56rosa’s picture

Hello,

Did you enable "Clean URLS" in "Administer"?

wxman’s picture

Yes I do have clean URL's on

briansea’s picture

The issue you probably had with the rewrite rules was escaping the existing backslashes.

This should do it:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/page/my-books/\\\
RewriteRule .* /page/my-books [L,R=301]

RewriteCond %{REQUEST_URI} ^/page/my-books/\\\/\\\
RewriteRule .* /page/my-books [L,R=301]
wxman’s picture

Thanks Brian, that did it. I've never been very good at regex, and you were correct, I didn't escape them.
Thanks.

wxman’s picture

I don't suppose there is a trick so this would work on several different file names? For example:
/page/my-books/\
/page/more-books/\
/page/my-other-books/\

I can do a rule for each one in my log, but I think that would be inefficient. Is there a way to use a variable, like %{REQUEST_FILENAME} to replace the file name in both Cond and the Rule?

briansea’s picture

This should do it:

RewriteCond %{REQUEST_URI} ^/page/(.*)/\\\
RewriteRule .* /page/%1 [L,R=301]

Any matches from the last RewrieCond get exposed in variables prefixed with %. Any matches from the RewriteRule get prefixed with $.

I hope this helps!

wxman’s picture

You are a lifesaver! I can't tell you how many searches I did looking just for how to use a variable, but I couldn't find one that made sense. This works great now. Of course I would love to find where on Amazon the bad link is coming from, but that could take a while.
Thanks again.

briansea’s picture

I know what you mean. You're welcome. :)