Forum Moderators: phranque

Message Too Old, No Replies

Rewrite rule to replace spaces with dash

         

crimson090

6:37 pm on May 19, 2008 (gmt 0)

10+ Year Member



Hello all,

I have a site where we are slowly changing URL's with spaces to dashes. So for instance, from "our%20company%20policy.aspx" to "our-company-policy.aspx".

I'd like any external links to these pages to redirect to the new pages. So I need a rewrite rule that will match two (or more) words separated by spaces and redirect to the same words, separated by dashes.

(I did a search for this topic and couldn't find such a rule, but sorry if I missed it).

Any suggestions would be very much appreciated. Thanks!

g1smd

6:50 pm on May 19, 2008 (gmt 0)

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



A literal space in a URL needs a preceding backslash in the rule to signal that it is really a literal space.

What is the maximum number of spaces that could appear in a URL?

Is the number fixed or variable?

crimson090

12:58 pm on May 20, 2008 (gmt 0)

10+ Year Member



Thanks for the reply.

The maximum number of spaces? I'd say 10 should cover the vast majority of our pages.

The number is variable though, hence the difficulty I have in creating this (I haven't done regular expressions in years!)

jdMorgan

4:37 pm on May 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This search for a related topic [google.com] here in this forum should help get you started.

Jim

[edited by: jdMorgan at 4:41 pm (utc) on May 20, 2008]