Sneha Dagli
Sneha Dagli

Reputation: 13

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/

Upvotes: 1

Views: 398

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

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>

Upvotes: 1

Related Questions