Search code examples
apache.htaccessmod-alias

Htaccess 301 Redirect a sub folder with exception


I would like to redirect to a sub-folder except a dir.

What I need is:

Redirect 301 /blog/ /blog-post/
#Exclude /blog/wp-admin/

Solution

  • You need to use RedirectMatch :

    RedirectMatch 301 ^/blog/((?!wp-admin).+) /blog-post
    

    This will redirect everything except blog/wp-admin .

    If you are on apache 2.4 you can also use Redirect inside if directive

    <if "%{REQUEST_URI} !~ m#/blog/wp-admin/#">
    Redirect 301 /blog/ /blog-post/
    </if>