Redirection regex not working in Rank Math

#759621
  • Resolved Jennica Musselman
    Rank Math free

    I just installed RankMath on a new site. The site was already using a plugin called Redirection to manage my redirects. When I installed RankMath, the Setup Wizard told me that it would import my redirects from Redirection, as well as deactivate Redirection, because the plugin was incompatible with RankMath.

    However, while Redirection was deactivated, RankMath did not import ANY of my preexisting redirects. The RankMath redirections page is completely blank. So I have to set up all my redirects again from scratch.

    My main redirect was a regex that converted old WordPress URLs that used a date structure in the URL to just the post type in the URL. I recreated the same source and target URL regex code in a new redirect in RankMath, but it is not working. This exact same code worked just fine as a redirect in the Redirection plugin. Can you tell me what needs to be changed for RankMath to use it correctly?

    Source URL: ^/\d{4}/\d{2}/\d{2}/(.*)
    Target URL: https://mydomain.com/$1
    (in the Redirection plugin, my target URL was just /$1 but RM forces the domain into the field)

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    I apologize for the inconvenience you are facing with the redirection regex in Rank Math. It seems like the regex you used from the Redirection plugin needs a slight adjustment to work correctly in Rank Math.

    In Rank Math, when setting up a regex redirect, you need to exclude the initial forward slash (/) from the Source URL. Here is the corrected regex format you should use in Rank Math:

    Source URL: ^d{4}/d{2}/d{2}/(.*)
    Target URL: https://example.com/install-plugin/`

    By removing the initial forward slash from the Source URL, the regex should work as expected in Rank Math. Please make this adjustment and try setting up the redirect again.

    If you encounter any further issues or need additional assistance, please feel free to reach out by assigning this ticket to a human agent using the available buttons.

    Thank you for bringing this to our attention.

    Sorry, but the bot solution did not work. I changed my settings to this, as instructed:

    Source URL (regex): ^d{4}/\d{2}/\d{2}/(.*)
    Destination URL: https://mydomain.com/$1

    I also tried both of the following variations for the source URL, but these didn’t work either:
    ^/d{4}/\d{2}/\d{2}/(.*)
    /^/\d{4}/\d{2}/\d{2}/(.*)

    In the Redirection plugin, I could use /$1 as the destination URL, which matches the format of the source URL (the exact string to replace). However, RankMath forces the domain into the field, and I am wondering if that might be why the redirect is failing.

    I found the solution in your documentation. Note that there are a LOT of incorrect pieces of code regarding this issue on various websites.

    However, the following worked for me in RankMath to direct a year/month/date/postname URL structure to just the postname URL structure:
    Source URL: \d{4}/\d{2}/\d{2}/(.*)
    Target URL: /$1/

    RankMath, PLEASE note that your AI bot gave a WRONG ANSWER.

    Replying and marked as resolved.

    Hello,

    Thank you for your input and observation.

    We are glad to know that this issue has been resolved. Thank you for letting us know.

    This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.

    We appreciate your patience and cooperation throughout this process.

    Thank you for choosing Rank Math.

Viewing 4 replies - 1 through 4 (of 4 total)

The ticket ‘Redirection regex not working in Rank Math’ is closed to new replies.