By ajamali
Hi,
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; }
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This should do the trick:
location ~ ^/wp-content/(.*) {
return 301 $scheme://example.org/$1;
}
This would redirect domain.com/wp-content/file1.jpg to example.org/file1.jpg If you want everything in your wp-content folder to redirect to a single location on the new server you can use this:
location ~ ^/wp-content/(.*) {
return 301 $scheme://example.org/$1;
}
Or if this is another server that has it’s own wp-content folder you can use this:
location ~ ^/wp-content/(.*) {
return 301 $scheme://example.org/$request_uri;
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.