Forum Moderators: phranque

Message Too Old, No Replies

301 redirect url with %20 space embedded

cant seem to match % or %20

         

peohk

8:20 pm on Mar 1, 2008 (gmt 0)

10+ Year Member



Hi everybody,

Need some help with a small but frustrating issue
Newbie so apologies if I have missed the painfully obvious

Some users have linked to my site using the correct urls
/images/Shot%2001.jpg
/images/Shot%2004.jpg
/images/All%20Colour.jpg

Am now on a new site and the corresponding urls are

/images/pic1.jpg
/images/pic2.jpg
/images/all.jpg

My redirect problem seems to be tied to matching the %20 (space) as other urls without %20 are redirecting fine

Have tried a few things such as
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^images/Shot\%2001.jpg?$ [myhost.com...] [R=301,L]

Also tried matching %20 with \ [:space:] [:blank:]
All with no luck

Am on hostgator shared server with full access to .htaccess , apache version 1.3.37 (Unix)

Help or pointers would be appreciated

Samizdata

9:11 pm on Mar 1, 2008 (gmt 0)

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



Spaces in filenames are a nuisance - try escaping with a backslash:

RewriteRule ^images/Shot\ 2001.jpg$ http://www.example.com/images/pic1.jpg [R=301,L]
RewriteRule ^images/Shot\ 2004.jpg$ http://www.example.com/images/pic2.jpg [R=301,L]

g1smd

10:50 pm on Mar 1, 2008 (gmt 0)

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



Minor typo. This might be slightly better:

RewriteRule ^images/Shot\ 01.jpg$ http://www.example.com/images/pic1.jpg [R=301,L]
RewriteRule ^images/Shot\ 04.jpg$ http://www.example.com/images/pic2.jpg [R=301,L]

Samizdata

11:05 pm on Mar 1, 2008 (gmt 0)

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



Haha - thanks!

I would say it would be infinitely better (because it will work).

peohk

4:34 am on Mar 2, 2008 (gmt 0)

10+ Year Member



Many thanks, now working.
Thought I had tried this but must have omitted something or added an extra space somewhere.

Nice clear example got it working first time

Thanks again

PS: Have learnt my lesson with spaces in filenames, never again

Samizdata

4:47 am on Mar 2, 2008 (gmt 0)

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



Apologies for the typo, but also for forgetting my manners.

Welcome to WebmasterWorld!