Forum Moderators: phranque

Message Too Old, No Replies

rewrite with spaces probs

I'm missing something...

         

walkman

5:14 am on May 8, 2005 (gmt 0)



following the advice here: [webmasterworld.com...]
I came up with this:
RewriteEngine on
RewriteRule ^Word1\ Word2-keyword$ /word1-word2-keyword [R=301,L]

but it's not working at all. It is between a few other rewrites that work so the error must be here

on the browser it shows with %20, and I tried with that too, but it still didn't work. What am I missing? I really don't want to lose about 10 or so deep links

Thanks,

jd01

5:34 am on May 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi walkman,

I think there are a couple of things you can try...

I see you are escaping the space, so you might try \s. If that does not work you might need to get a little more creative.

What may work, and since you do not need to 'catch' the space in a variable is a simple regex that would make your rule look like this:

RewriteRule ^Word1[^a-z-]+Word2-keyword$ /word1-word2-keyword [NC,R=301,L]

The regular expression should kick in and catch the space because it matches anything that is not a letter or a '-'. It also should not impact your server load too much, because it is in the middle of the line and forward looking to what should be the next character to 'break' it.

Hope this helps.

Justin

Edited: Clarity and regex to include any character(s) up to the next letter.

walkman

5:45 am on May 8, 2005 (gmt 0)



Hi Justin,
still doesn't work. The \s gives a bad delimiter error and the other one still shows 404...

strange

jd01

6:24 am on May 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't realize it was a 404 error that was being generated... (I assumed 500)

Is the address being changed in the browser? If it is, you are not sending requests to the correct location. If it is not, please let me know. (Is it something simple, like no file type in the rule?)

Justin

walkman

3:04 pm on May 8, 2005 (gmt 0)



Ok,
here's how it was solved . The 404 was because I had removed the old rewrite rules, so I created a file instead of messing them up.

It still didn't work so I created a Word1%20Word2-keyword folder, with a index.php that gives a 301 to the new file. The only "problem" is that spiders first get a 301 to Word1%20Word2-keyword/ (with the / on end) and then one more 301 to the new file. Will they follow to 301s? I tried a spider simulator via "HTTP Viewer" and the followed it but I'll find out later if GoogleBot etc. do the same

thanks again,