• Resolved davidensor

    (@davidensor)


    Is there a way to catch and redirect mixed-case URLs in a single redirect rule? For example, I’d like to have a single rule for two scenarios:
    /path/to/url/ and /Path/to/url/ (‘P’ vs ‘p’).

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try this:
    Source: ^(\/path\/to\/url)(.*)gi
    Target: /path/to/url$2

    That matches “/PaTH/to/UrL/foo” and returns “/path/to/url/foo”.

    The surrounding ticks are delimiters. A regex can be surrounded by many different defined delimiters like @ or % or \`. After the regex is a flag that says overall how the regex is processed. The ‘g’ says everything must match in some way rather than having it do the redirect just based on the first match available. The ‘i’ says the entire regex is case insensitive.

    For individual characters, use a syntax like [a-zA-Z], which means a single character can be any A-Z character, upper or lower case. If you just want to match the P in Path, for example, in a case-insensitive mode, use something like “\/[pP]ath…”.

    HTH

    • This reply was modified 7 years, 7 months ago by Tony G.
    • This reply was modified 7 years, 7 months ago by Tony G.
    • This reply was modified 7 years, 7 months ago by Tony G.
    • This reply was modified 7 years, 7 months ago by Tony G. Reason: Needed to escape backticks to get them to display

    The site is eating my responses here, probably because the regex looks threatening. I’ve reposted a few times in the hope of getting it to be more acceptable. I hope this doesn’t show duplicates…

    Try this:
    Source: %^(/path/to/url)(.*)%gi
    Target: /path/to/url$2

    That matches “/PaTH/to/UrL/foo” and returns “/path/to/url/foo”.

    The surrounding ticks are delimiters. A regex can be surrounded by many different defined delimiters like @ or %. (I tried to use escaped backticks here but this site filtering really doesn’t like it. After the regex is a flag that says overall how the regex is processed. The ‘g’ says everything must match in some way rather than having it do the redirect just based on the first match available. The ‘i’ says the entire regex is case insensitive.

    For individual characters, use a syntax like [a-zA-Z], which means a single character can be any A-Z character, upper or lower case. If you just want to match the P in Path, for example, in a case-insensitive mode, use something like “\/[pP]ath…”.

    HTH

    • This reply was modified 7 years, 7 months ago by Tony G. Reason: Had to fix backticks intercepted by the site
    Thread Starter davidensor

    (@davidensor)

    Sorry so slow to respond…
    I did try that approach, Tony, but didn’t have success with it working at all (maybe something to do with the way it was captured in the comment?).
    I did further digging and this approach – (?i)^/path/to/url(.*) – seemed to do the trick, though. Thanks, Dave

    WOW! I’ve never seen that syntax: (?i)...
    Looking it up, it’s certainly documented. And while looking that up, I found some other interesting tidbits that might help folks here.

    Note on that same page, that there is an option to allow multi-line patterns, also known as “Free-Spacing” mode. To us this means a single text box for the Source is an artificial limitation, both in the plugin and here when we’re documenting our RegEx. It means that TextBox should be a TextArea where we can break more complex regex into multiple lines for readability and documentation. I think that would help many users of this plugin to learn and use the tools more effectively.

    @johnny5 ?

    Thanks and you’re welcome. XD

    • This reply was modified 7 years, 7 months ago by Tony G.
    Plugin Author John Godley

    (@johnny5)

    The plugin will eventually have an ignore case option:

    https://github.com/johngodley/redirection/issues/166

    A multi-line target URL sounds like a complicated solution to me.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to catch mixed case URLs for 301 redirection’ is closed to new replies.