-
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.Example
From:^/knowledge-centre/reports(.*)$
saved in htaccess asknowledge-centre/reports(.*)
To:/reports$1
Test:/knowledge-centre/reports/report-name-here
No match – goes to default pageEntering
#^/knowledge\-centre/reports(.*)$#
saves to htaccess as^/knowledge\\-centre/reports(.*)$
also no match
Entering ‘Starts With’/knowledge-centre/reports
saves to htaccess asknowledge\-centre/reports
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.From:
^/news/press-releases(.*)$
To:/press-releases$1
seems to mostly work (which is weird because it has a hyphen)
Matches/news/press-releases/article-name-here
Does NOT match/news/press-releases/
or/news/press-releases
Expected: $1 should capture the trailing slash or empty string and append to the new URL so/news/press-releases/
goes to/press-releases/
and/news/press-releases
goes to/press-releases
The ticket ‘How is regex translated?’ is closed to new replies.