Can someone help with dynamic redirect rules (regex)?

[ad_1]

I am a front-end developer launching a site that is replacing an old site. I am having a hell of a time with the redirect rules for the dynamic URLs from the old site. After a couple hours of trial and error, I am posting here to see if someone can show me the missing character or error in my approach.

Old site page URL: [https://www.mysite.com/teacher-profile?name=JoeSchmoe&teacher=69])

Desired redirect URL: [https://mysite.com/directory-teachers]) (static page where they can find the teacher)

What is currently happening when I redirect “/teacher-profile?name=JoeSchmoe&teacher=69” to [https://mysite.com/directory-teachers]):

[**https://mysite.com/directory-teachers**]

The dynamic string is appended to the end of the destination. This URL doesn’t exist and so 404s. How can I make the redirect work without it appending the dynamic info from the source?

Thank you for reading this far! Happy to clarify anything that isn’t clear here.

[ad_2]
4 Comments
  1. Hi, may I ask why are you not using e.g. 301 redirects plugin? It’s a more convenient way.

  2. You might try the following in your functions.php and see how that does

    `add_rewrite_rule(‘^directory-teachers/(.*)/(.*)?’, ‘index.php?pagename=directory-teachers&name=$matches[1]&teacher=$matches[2]’, ‘top’);`

  3. You better ask Chat GPT humans take too long to figure this out and Chat GPT is real good at it.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer