Forum Moderators: phranque

Message Too Old, No Replies

Spaces in filenames

         

Dexie

3:51 pm on May 23, 2005 (gmt 0)

10+ Year Member



Has anyone here ever experienced another website linking to you with a space in the filename that they use to link to you please? Did you ever find a solution?

I have access to my .htaccess and I'm on Linux based servers.

It's crucial that the solution is compatible with Google, Yahoo and MSN.

This has been driving me absolutely mad over the last few weeks and I can't seem to be able to solve it. The webmaster of the other site is uncontactable and I can see the errors in my logs and going by the amount, it's something that I really need to get done as quickly as possible.

Any help very much appreciated.

Sev.

jdMorgan

5:05 pm on May 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just 301 Redirect the incorrect URL using mod_rewrite. Look for ^([^\ ]+)\ (.+$) as the pattern.

See our forum charter [webmasterworld.com] for some references.

Jim

Dexie

9:28 am on May 24, 2005 (gmt 0)

10+ Year Member



Many thanks Jim, and thanks also for the link.

I'm getting a little confused, I have this in my .htaccess (which isn't working):

RewriteRule ^firstword%20secondword/?$ [example.com...] [R=301,L]

The incorrect link on the other site is, for example:
[example.com...] secondword/

Are you saying that I should replace the %20 with one of the characters below please?

^([^\ ]+)\ (.+$)

Any help very much appreciated.

Sev.

zooloo

10:33 am on May 24, 2005 (gmt 0)

10+ Year Member



Why not email those with spaces in your URL and ask them to use the correct one.

Perhaps I misunderstand this.

zoo

jdMorgan

2:10 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



E-mailing the other webmasters is a good idea. Unfortunately, only a few will respond. And then it may take many months for the old URL to disappear from search engine listings.

> Are you saying that I should replace the %20 with one of the characters below please?

^([^\ ]+)\ (.+)$

One of the powerful features of mod_rewrite is that it includes regular-expressions pattern-matching. You can write one RewriteRule that will remove a space from *any* URL requested from your server. In this case the pattern above says, "Match one or more of any characters, except for a space, and save those characters in a variable. Then match a literal space (this is written as "\ "). Then match one or more of any additional chararacters, and save those in a second variable. You use it like this:


RewriteRule ^([^\ ]+)\ (.+)$ http://www.example.com/$1$2 [R=301,L]

This code removes the space from any URL, because the new URL on the right side uses the characters before and after the space, as saved in the variables "$1" and "$2". It only removes one space at a time, but it works for any URL that has characters, then a space, then more characters.

If you only need to fix one URL, then a specific solution would be:


RewriteRule ^firstword\ secondword/?$ http://www.example.com/firstwordsecondword/ [R=301,L]

the only change to your code being the specification of the space as "\ " instead of %20 -- again see the references in our charter.

Jim

Dexie

6:43 pm on May 24, 2005 (gmt 0)

10+ Year Member



From the first post:

"The webmaster of the other site is uncontactable"

Dexie

6:46 pm on May 24, 2005 (gmt 0)

10+ Year Member



Many thanks Jim, I'll now get to work on this straight away.

Dexie

8:47 am on May 25, 2005 (gmt 0)

10+ Year Member



Many thanks Jim, it works perfectly.

Most of the time, this subject is a little beyond my understanding, but you are a great help to me and once again, you've been excellent in explaining the solution.

Sev.