Redirect any and all traffic to a folder to another url

December 20, 2017 281 views
Nginx Ubuntu


I am on Ubuntu 14.04.5 running Nginx 1.12.1.

I have a wordpress site, I would like to do the following:

Site A: example.com
Site B: example.org

I would like to redirect any traffic to example.com/wp-content/* to example.org. This includes all subrectories and files (pdf, mp3, etc.)

If the url they are accessing is pointing to example.com/wp-content/folder1 or to example.com/wp-content/folder2/file.pdf, I want everything to be redirected to Site B.

I have tried the following, which redirects anyone accessing example.com/wp-content/ but not if they have the full url to a file:

location ^/(wp-content.) {
rewrite ^/(wp-content.
) example.org permanent;

Be the first one to answer this question.