Categories
Development WordPress

Using RedirectMatch in Your .htaccess File

Here is a quick overview of how to redirect URLs in your htaccess file using RedirectMatch (regex).

Firstly, here’s an example of a RedirectMatch redirect:

RedirectMatch 301 ^/services/?$ https://www.yezzoo.com/

Now let’s break this down:

  • RedirectMatch – This states we want to base the redirect on a regular expression (also known as regex), the redirect will occur if a URL matches the regex.
  • 301 – Type of redirect. 301 is a permanent redirect (stating the page has moved forever).
  • Regex. Here are the symbols used in this example and their meanings.
    • ^ – Match anything before this character
    • ? – Match with or without the previous character, so in this example it would match /services or /services/
    • $ – End of url, do not match anything after this character.
  • URL – The destination URL where you’d like traffic to any pages that meet the regex condition redirected to.

I hope this is helpful.

By Andy Corby

Hi, I'm Andy and I am a Digital Marketer and Full Stack Web Developer, with a BA (Honours) Business & Finance Degree (2:1) and 10+ Years Experience in Marketing and Development.

Leave a Reply

Your email address will not be published.

four × 2 =