Jamie
Jamie

Reputation: 47

HTACCESS - Redirect with non alphanumeric characters

I have a website linking to mine with a really badly formed URL: http://my-example.com/<br />. It looks like the developer of the site linking to mine has messed up their coding and has let a line break tag end up in the middle of href attribute of the link.

I've not had problems with redirecting URLs with non-alphanumeric characters, the only issues is the space in the <br />.

The Redirect line is:

Redirect 301 category-name/<br /> http://example.com/new-url

The space in the <br /> will be mis-interpreted by the server as the delimiter between the request URL and new URL.

Is there a way I can make the space in <br /> be treated as part of the URL, similar to how the backslash works in RegEx, or do I need to take a different approach to this?

The url leads to a dead page, so needs to be redirected nonetheless.

I tried looking at: Remove Characters from URL with htaccess and Remove Characters from URL with htaccess along with a few others but these don't seem to help, particularly the second not solving the issues with spaces in the URLs.

Upvotes: 1

Views: 270

Answers (1)

anubhava
anubhava

Reputation: 786359

You can use RedirectMatch and then use \s for matching space:

RedirectMatch 301 "category-name/<br\s/>" http://example.com/new-url

Upvotes: 1

Related Questions