Forum Moderators: phranque

Message Too Old, No Replies

When redirect doesn't work, what's my next choice

changing page names which included spaces

         

kevinpate

4:29 am on Mar 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, when I came onto the scene, numerous pages were already named with a space in the name, e.g. domain/directory/word1 word2.htm

Typically what has happened to date is these pages are altered by the user's browser to the following: domain/directory/word1%20word2.htm

It was recently suggested to me that a space in the page name was something I needed to take action on, so I have, in this manner.

Renamed each such page to domain/directory/word1-word2.htm
Loaded pages via ftp, but left old pages up as well, so directory now contains:
domain/directory/word1%20word2.htm AND
domain/directory/word1-word2.htm
for each such page. Pages are identical except for the page name.

Applied a Permanent Redirect so that requests for:
domain/directory/word1 word2.htm
GO TO
domain/directory/word1-word2.htm

That dinna work, so I switched the 301 st that requests for:
domain/directory/word1%20word2.htm
GO TO
domain/directory/word1-word2.htm

That dinna work either.

So, still being a confuzzled owner and wearer of a Near Total Newbie button, I don't know what to do next. I don't want, or need the pages to be duplicated except for title, but I don't know what to do next to fix this mess.

Any workable solution would be greatly appreciated

jdMorgan

4:59 am on Mar 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kevinpate,

You could try


RedirectMatch /directory/word1\ word2\.html http://example.com/directory/word1-word2.html

which uses regular expressions, thus allowing you to escape the space character. I really don't know if this will work since I've never tried it, but it's worth a shot.

A similar approach might work using mod_rewrite instead of mod_alias.

In either case, you may be able to make use of backreferences to simplify the job of redirecting a large number of pages:


RedirectMatch /directory/(^\ )*\ (.*) http://example.com/directory/$1-$2

If the basic idea above works at all, the above redirect will accept anyword1 and anyword2.html in /directory, and change the space between them to a hyphen.

HTH,
Jim