'Redirect Page Path to Homepage using .htaccess

How can I redirect all of the sub pages that include a particular path (/home-2016/) back to my home page? I am using the below code in my .htaccess file, but it is not working. I can't seem to find a solution.

I want to redirect the following

  1. https://www.example.com/home-2016/ to https://www.example.com
  2. https://www.example.com/home-2016/... to https://www.example.com

RewriteRule ^home-2016/(.*) / [R=301,NC,L]


Solution 1:[1]

RewriteRule ^home-2016/(.*) / [R=301,NC,L]

This rule already does as you require, but it would seem you were putting the rule in the wrong place. Redirects like this would need to go near the top of the .htaccess file, before any existing rewrites (like a CMS front-controller pattern).

However, this rule can also be simplified, since you don't need the capturing subpattern.

The following will do the same, but with a more efficient regex:

RewriteRule ^home-2016/ / [R=301,NC,L]

Unless you specifically need a case-insensitive match, you should remove the NC flag.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrWhite