How do I 301 redirect all pages to another domain except for two sub-directories?
Asked
Active
Viewed 27 times
0
-
1Please provide your current rules or try something on your own and put it here. – Abhishek Gurjar May 30 '17 at 05:50
-
1`RewriteRule !^(?:dir1|dir2)($|/) http://example.com%{REQUEST_URI} [L,R=301,NE,NE]` should work – anubhava May 30 '17 at 05:50
-
Perfect. Thanks @anubhava. Add an answer if you like. – Steve May 30 '17 at 05:57
1 Answers
0
You can use this redirect rule in site root .htaccess:
RewriteEngine On
RewriteRule !^(?:dir1|dir2)($|/) http://example.com%{REQUEST_URI} [L,R=301,NC,NE]
!^(?:dir1|dir2)
is negation match that excludes dir1
and dir2
from this redirection.

anubhava
- 761,203
- 64
- 569
- 643