• Resolved gsibert

    (@gsibert)


    Having trouble getting a regex to work. The old url was something like /alabama/ and it’s moving to /new-slug/alabama/

    If it was just 1 it would be simple but let’s say it’s all the states.

    From:
    /(alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nebraska|nevada|newhampshire|newjersey|newmexico|newyork|northcarolina|northdakota|ohio|oklahoma|oregon|pennsylvania|rhodeisland|southcarolina|southdakota|tennessee|texas|utah|vermont|virginia|washington|westvirginia|wisconsin|wyoming)

    To:
    /new-slug/$1

    end up with:
    /new-slug/new-slug/new-slug/new-slug/new-slug/new-slug/

    I’m sure I’m missing something in the from regex, maybe?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Jeffrey Paul

    (@jeffpaul)

    @gsibert I’d recommend checking out the linked great tutorials on regular expressions from the readme. Good luck!

    Thread Starter gsibert

    (@gsibert)

    I’ve been reading those for 2 hours… thanks for the helpful tip.

    Thread Starter gsibert

    (@gsibert)

    Since support is so useful here, I’ll post what I found to work after spending the rest of the day… when you suck at regex it takes all day to figure 9 characters:

    ^[^\/]?\/(alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nebraska|nevada|newhampshire|newjersey|newmexico|newyork|northcarolina|northdakota|ohio|oklahoma|oregon|pennsylvania|rhodeisland|southcarolina|southdakota|tennessee|texas|utah|vermont|virginia|washington|westvirginia|wisconsin|wyoming)

    in the to:

    /your-slug/$1

    The upper query only grabs the states at the root URL, not query strings or other slugs. That’s what was causing my loop.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect loop’ is closed to new replies.