• Resolved justmeandmyself

    (@justmeandmyself)


    Hi John,

    first of all I really like your plugin, it’s the best one I’ve seen and seem to be very powerfull!

    I would like to ask you some questions regarding regular expressions (not to explain it to me, just to clarify some things). I’m no expert, but I have a decent understanding of regex and that’s why your plugin confuse me a little.

    My questions:
    What’s the correct syntax for redirecting from my root domain to another page with regex?

    For example, I can redirect my URLs without regex enabled from:
    https://my-website.com/ -> https://my-website.com/any-page

    But I can’t by using regex. Do I always need to use this syntax e.g.?:
    ^/(.*) -> /any-page/

    Further if I try to match URLs like “https://my-website.com/” with regex it doens’t seem to work. It should be targeted by following syntax:
    ^(.*)(my-website\.com)(.*)
    but it doesn’t work. When I try it on “https://regex101.com/” it works.

    So I don’t quite understand why it wouldn’t work. I know these are not the best examples or “best practises”, but just to bring my point over.

    Maybe you or someone else can answer these questions. I’m just confused by the documentation when it states here (“https://redirection.me/support/redirect-regular-expressions/”) syntaxes like: “^/oldpage/(.*)”. By that I thought you would mean by “oldpage” a normal URL (http | https | www | _). And by that I thought you would mean the following example would give me the same result, but it doesn’t:

    ^/oldpage/(.*) = ^(.*)(my-website\.com)[\/]?(.*)

    So maybe you can give a short explanation to this. I already could read in the comments of some other posts, that we aren’t supposed to use the domain name in the syntax, but only trailing slashes to target the domain

    My final question and the reason I downloaded that plugin. I made to work, but still need a clarifycation if somebody could answer that question. I wanted to redirect all my users based on their user agent (IE11 and all versions below) to an information page. The redirect works thanks to the documentnation. But I’m not sure if my solution is the best and there I would like to know if that redirect is OK?:

    ^/(?!new-page)(.*)$ -> /new-page/

    By that I wanted to redirect the user from every page but the targeted page to the new page. Is that expression good enough for that purpose?

    Sorry for the long post. I know your time is limitted, therefore anybody with some knowledge regarding that topic is welcome to answer.

    Much regards
    Max

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Godley

    (@johnny5)

    I think maybe you are overthinking this a little.

    But I can’t by using regex

    Why can’t you?

    What’s the correct syntax for redirecting from my root domain to another page with regex

    Why do you need to use a regex? Putting / as the non-regex source is sufficient.

    By that I thought you would mean by “oldpage” a normal URL (http | https | www | _

    No, it means what is written in the documentation – the path of the URL. The domain has already matched by fact of the request having reached your website.

    But I’m not sure if my solution is the best and there I would like to know if that redirect is OK?:

    There are many ways of doing something. If it works for your needs then it’s fine.

    Thread Starter justmeandmyself

    (@justmeandmyself)

    @johnny5 Hey thank you for your answer,

    I think you’re right, I was overthinking my use case a little. It’s not that I couldn’t use regex, it’s only that I couldn’t use it as I would’ve expected it and it took me a little bit too long to understand it. Now that I’ve solved my use case I’m satisfied, but couldn’t let it slide without asking for a little of a feedback ??

    I think I needed regex to target every URL of mine website, so I would write it in that manner /*. without the * it wouldn’t target any other pages besided the home page itself. I didn’t know any other way to achieve besides regex.

    And I think I will let it go now with solving my use case and after getting a better understanding of the plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Regex – Not working as expected’ is closed to new replies.