• Resolved abitofmind

    (@abitofmind)


    I tried setting up an enforced redirection of URLs with a single uppercase letter to the canonical URL in all lowercase. Your plugin gave these two recommendations:

    • To prevent a greedy regular expression you can use ^ to anchor it to the start of the URL.
    • Your target URL should be an absolute URL like https://domain.com/$1 or start with a slash /$1 .

    Took this advise to heart. Reshaped my RegEx to:

    ^/(.[A-Z]+.)/\L$1

    • Request: /testing-wordpress/Sample-Page/
    • 10 seconds of inactivity. Then my browser shows this:
    • Address bar: /LLLLLLLLLLLLLLLLLLLLtesting-wordpress/Sample-PAge/
    • Body: “too many redirects” error message.

    It seems the Redirection plugin does not support the case transformation operators like \L “to lowercase” in its Replacement Patterns. Instead it seems to have inserted a literal L. Hence it matches itself (uppercase again!) and this leads to an infinite loop. Until at the 20th loop iteration, where a mechanism in the web browser killed this infinite loop.

    Your plugin support article on Regular Expressions does not mention “Case Transformations” in any form. I guess they are not supported.

    • Could you add support for them?
    • Or tell me if there is any other way to achieve this case transformation?
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter abitofmind

    (@abitofmind)

    The RegEx I used was actually:

    ^/(.*[A-Z]+.*)?→??/\L$1

    In my previous post the asterisk characters were eaten up and interpreted as an italics tag like in Markdown syntax.

    Plugin Author John Godley

    (@johnny5)

    The plugin uses PHP regular expressions. You can consult PHP for a full list of what is supported.

    You can find out more about transformations here: https://redirection.me/support/dynamic-urls/

    Thread Starter abitofmind

    (@abitofmind)

    Ad 2) Your proposed solution to use shortcut syntax in the replacement pattern as /[lower]$1[/lower] does the job perfectly!
    → Now all URLs with wrong capitalization get redirected to the canonical lowercase URL with a HTTP 301 redirect. Thanks for your support!

    Ad 1) PHP’s RegEx implementation has no case transformation operators but for this rather uses callbacks where it then uses PHP’s strtolower() function.

    So I guess performance wise solutions 1 + 2 are similar anyhow, as they happen within WordPress scope. Passing through the shortcut processing route is a slight overhead. But the calling of the callback is also an overhead. So comparable. Eventually they both end up in strtolower() or something similar anyhow.

    3) The only other way to do URL transformations would be entirely in the Webserver scope before touching WordPress, e.g. with Apache mod_rewrite and there apply the same rule:

    • RewriteCondition: The URL belongs not to any other scope but to WordPress (You as the webmaster can rule out patterns which belong to other destinations).
    • RewriteRule: If it contains a single uppercase letter, then transform it to lowercase (which are the canonical URLs in WordPress).
    • Problem: You create a redirect with the uncertainty of whether that target is a valid resource in WordPress. So “HTTP 301 Moved permanently” would be semantically wrong.
    • Considerations: Use the semantically correct error code for that “generic redirection with an uncertain outcome” which is then answered by WordPress by either 200 or 404.
    • But these my rambling of uncertainty show that the approaches 1+2 which work entirely within WordPress scope are the correct way to do an enforced redirection of WordPress URLs. If at all, because you recommended against this anyhow.

    Now I can collect a redirection log for 1-2 years and then tell you how often a case-transformation redirection has occurred indeed. If your predictions are true then most likely it will turn that I worried for nothing. But now I have an evidence-based tool in place at least. ?? Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘RegEx case transformation operator in replacement pattern of Redirection Plugin’ is closed to new replies.