user2336206
user2336206

Reputation: 3

Apache, redirect directory but keep sub-directory un-redirected

In Apache, is it possible that I can redirect a directory on my website to a new address, but keep sub-directories un-redirected?

For example, I wish to redirect accesses to files under

https://www.example.com/folder/ to
https://www.newexample.com/folder/

i.e. from

https://www.example.com/folder/abc.html to
https://www.newexample.com/folder/abc.html

But keep the access to its sub-folders unchanged? https://www.example.com/folder/subfolder/123.html will not be redirected.

Many thanks!

Upvotes: 0

Views: 164

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74028

You can exclude subfolder requests with a RewriteCond

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder/.*?/
RewriteRule ^folder/ https://www.newexample.com%{REQUEST_URI} [R,L]

Upvotes: 1

Related Questions