Using Regex for redirects

Torey Heinz's Avatar

Torey Heinz

03 May, 2010 03:02 PM via web

I have inherited a couple sites with 100+ pages of content I would like to convert them to Harmony, but my client is very concerned about not messing the content that has already been indexed by Google. So I will need to create many redirects...maybe.

For many of pages I should be able to use a regex. If the path is the same minus the .html, but I have failed at my attempts so far.
I think I want to do:
\/(specifications).html -> /(\1)/
but that doesn't seem to work.

What are your thoughts?

  1. Support Staff 2 Posted by Steve Smith on 03 May, 2010 04:13 PM

    Steve Smith's Avatar

    Likely, your regix is going to look like this: \/(.*)\.html -> /\1/

    The . character represents any character in regex, so that should be pretty greedy, but convert any /path/to/whatever.html file to /path/to/whatever/

  2. 3 Posted by John Nunemaker on 03 May, 2010 04:17 PM

    John Nunemaker's Avatar

    I don't know if it works with the slash at the beginning. Try removing that
    (\/) as well. I need to make it so it works with or without the slash.

  3. 4 Posted by Torey Heinz on 03 May, 2010 05:41 PM

    Torey Heinz's Avatar

    OK, my regex above is totally wrong, I can admit it ... I won't even edit it to save face :)

    Here is what worked
    (.*)\.html -> /\1/

  4. Support Staff 5 Posted by Steve Smith on 03 May, 2010 06:39 PM

    Steve Smith's Avatar

    You're close on your first one. Try this:

    (.*)\html -> \1/

  5. Torey Heinz closed this discussion on 19 Jul, 2010 11:15 PM.

Comments are currently closed for this discussion. You can start a new one.

Recent Discussions

17 May, 2012 10:45 PM
20 Mar, 2012 05:05 PM
26 Apr, 2012 01:40 AM
07 Mar, 2012 04:42 PM