D
D
DmitryLife2021-09-10 11:42:36
htaccess
DmitryLife, 2021-09-10 11:42:36

How to make an exception for one directory in HTACCESS?

Good afternoon, there is a task to make a redirect from one domain to another for all pages except for one directory like oldsite.ru/directory.

This solution completely redirects all requests to another domain:

RewriteCond %{HTTP_HOST} oldsite.ru
RewriteRule (.*) https://newsite.ru [R=301,L]


But how to make an exception for one directory?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2021-09-11
@shambler81

RewriteCond %{HTTP_HOST} oldsite\.ru
RewriteCond %{REQUEST_URI} !^/directory(/|)
RewriteRule (.*) https://newsite.ru [R=301,L]

sign ! - negation
(/|) - with or without a slash, but it is not necessary
\.ru - escape dots in %{HTTP_HOST}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question