Forum Moderators: phranque

Message Too Old, No Replies

Redirectmatch to deal with spaces

Redirectmatch to deal with spaces

         

sjd256

9:08 pm on Jan 27, 2009 (gmt 0)

10+ Year Member



Hi all,

Sorry to bring this one to you for my first posting :-(

Have been pulling my hair out on this one - so here goes:

Ok so recently someone has sent me about 200+ photos of a
recent charity event we held. The photos & loads of html
pages don't follow the normal naming convention in that
they have spaces within the names.

Some examples:

jon & lisa IMG_740.jpg
jon & lisa & dave IMG_741.jpg

also

jon & lisa & dave IMG_741_jpg.htm

etc etc

They are contained within a directory /charity/

This issue is with %20 that is used instead of the space
as the photos & pages can't be found at the moment.

How would I use redirectmatch in .htaccess so that I am
able to link to the images and files correctly for this
directory only?

Have tried Googling it but don't seem to be able to get it
right.

Many thanks in advance for any assistance you can offer.

Thanks

Steve

jdMorgan

9:51 pm on Jan 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The HTTP protocol requires that spaces in URLs be encoded as %20, so you're fighting a losing battle, here. I strongly suggest that you rename those images, using hyphens instead of spaces. Since hyphens are allowed in URLs, there will be no more problems with encoded characters in your URLs.

We've discussed code for replacing various characters (such as underscores and spaces) with hyphens many times before, so I commend the "site search" link at the top of this page to you.

Take a look at the resulting threads, modify the code to suit, and post if you have any difficulties.

Jim

wilderness

1:18 am on Jan 28, 2009 (gmt 0)

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



I strongly agree with Jim about the renaming of files.
In fact a stricter renaming would be even more beneficail to your website and its visitors.

Perhaps a two-letter prefix followed by a numerical sequence of "0001 thru 0200".
The logic for this is that in the event the SE's index your images with names in the file-names?
Your going to get unwanted visitors searching your site for
"jon, lisa or dave" (your examples).

The benefits to the prefix-numerical names is that paths will be much easier.
Of course you'll need to create an offline index with old names and new prefix-numbers.

g1smd

1:26 pm on Jan 28, 2009 (gmt 0)

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



Always avoid spaces and underscores in URLs.

Rename the files.

Tell your content suppliers the name format you require in the future.