Is there a reference to how RankMath translates redirections with the ‘Regex’ option?
It’s not working as expected. I have tried all these combinations with and without escaping, with and without delimeters, etc. If you could tell me the correct way to enter regex for best results, I can then test more reliably. I’ve been trying to troubleshoot by exporting to htaccess to see the generated regex, which seems to be translated differently depending if you choose Regex or one of the other options – Exact, Contains, Starts With, Ends With – vs Regex.
I’m having the following issues:
URLs with hyphens
-don’t seem to work when ‘Regex’ is selected. Probably because
-is a special character that needs to be escaped; however, if I add a backslash
\-, it gets double escaped as
\\-and the hyphen still doesn’t match. Hyphens are properly escaped as
\-if I use the ‘Contains’ option.
^/knowledge-centre/reports(.*)$saved in htaccess as
No match – goes to default page
#^/knowledge\-centre/reports(.*)$#saves to htaccess as
also no match
Entering ‘Starts With’
/knowledge-centre/reportssaves to htaccess as
which does match, but captures don’t seem to work.
String start/end anchors
^$are stripped out in the generated htaccess unless pattern delimiters are added. Does this mean anchors are ignored when processing the regex? If the matching is using PHP preg_match, should I include delimiters for more reliable results?
See above examples.
Captures – do captures work for Exact, Contains, etc, or only for Regex type?
When using regex, captures work unexpectedly – seem not to capture trailing slashes or empty string; if the capture is empty the capture expression is passed as a literal which breaks the URL and redirects to the default.
seems to mostly work (which is weird because it has a hyphen)
Does NOT match
Expected: $1 should capture the trailing slash or empty string and append to the new URL so
You must be logged in to reply to this ticket.