Reputation: 3
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
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