Forum Moderators: phranque

Message Too Old, No Replies

Really struggling with strange rewrite

         

norristudor

12:45 pm on Dec 4, 2010 (gmt 0)

10+ Year Member



I have some links to my site which are
http://mysite.com/%20


These are generating 404s

I want to redirect them to the root (or any valid page) and return a 200 code.

The problem is every rule I try doesn't work and I think its because apache sees the URL as a space.

This is what I've tried:
RewriteRule ^(%25*20) /newurl


RewriteCond %{QUERY_STRING} ^\%2520
RewriteRule ^/%2520 /newurl


RewriteCond %{THE_REQUEST} ^\%2520
RewriteRule ^/%2520 /newurl


Can anyone help with this one?

g1smd

1:51 pm on Dec 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The URL *is* a space, and is caused by a page either on your site or on some other site linking to "http://example.com/ " instead of linking to "http://example.com/".

There is a lot of forum and blog auto-linking plug-ins with poor pattern matching that can cause this.

Something like this might help...
RewriteRule ^\ $ http://example.com/ [R=301,L]

RewriteRule ^%20 http://example.com/ [R=301,L]

[edited by: g1smd at 1:55 pm (utc) on Dec 4, 2010]

norristudor

1:53 pm on Dec 4, 2010 (gmt 0)

10+ Year Member



well if I look at the actual anchor of this link to my site. it is written as
http://mysite.com/%20
- so yes I know its a space. But when it hits my site it throws a 404.

Thats what I want to prevent.

norristudor

1:57 pm on Dec 4, 2010 (gmt 0)

10+ Year Member



just seen your edits... let me try that.

norristudor

2:03 pm on Dec 4, 2010 (gmt 0)

10+ Year Member



g1smd
The first one worked!

You are one awesome guy! Thats done it. You have no idea how long I have been struggling with this stupid rule and overcomplicating.

thanks again.