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.andycorby.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

Being quick to learn, I am a confident team member, who is responsible and easy to get on with; the kind of hardworking person who is always thinking ahead and using initiative.

Experience in a range of direct and digital marketing techniques. Google AdWords Certified and I hold a BA(Hons) Business & Finance degree (2:1).

Key skills include: Google AdWords PPC (aka Google Ads); search engine optimisation (SEO); LinkedIn lead generation; web design; user interface (UI) and user experience (UX) design; software development; server management; and development experience with: HTML, CSS, PHP, MySQL, JavaScript, JQuery, AJAX, BootStrap, PHPMyAdmin, PhantomJS, CasperJS, VPS/VPC(Ubuntu 16.04 LTS).

Special interest in maximising productivity through: agile working, productivity tools, levaging time, and automating set processes.

Leave a Reply

Your email address will not be published. Required fields are marked *

12 + 8 =