Regex – Not working as expected
-
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-pageBut 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
- The topic ‘Regex – Not working as expected’ is closed to new replies.