I want to 301 redirect a bunch of files from a subdomain to another domain. This is my .htaccess file, can someone supply the code that works with nginx
RewriteEngine on
RewriteCond %{HTTP_HOST} ^media.ahemahem.com$ [OR] RewriteCond %{HTTP_HOST} ^www.media.ahemahem.com$ RewriteRule ^(.*)$ “http://www.ahemahem.com/wp-content/uploads/$1” [R=301,L]
and where should I add this code? I’ve set up a A record (media) for the domain (ahemahem.com) at digitalocean and I’ve set my main domain too. I’ve installed Wordpress on ahemahem.com using Easy Engine which works on Nginx.
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!
Google is an amazing thing. It finds you things like http://winginx.com/en/htaccess that turn your .htaccess rewrites into nginx configuration that looks like this: <br> <br># nginx configuration <br>location / { <br>if ($http_host ~ “^media.ahemahem.com$”){ <br>rewrite ^(.*)$ /“http:/www.ahemahem.com/wp-content/uploads/$1” redirect; <br>} <br>} <br> <br>It goes in your config file.
Yeah, already tried that stuff which didn’t work and resulted in my server failing and all my sites went down. So I asked here. It was supposed to go in the nginx.conf files right? In the main /var/www/site.com/nginx.conf or etc/nginx/nginx.conf? I tried on both. In site.com it doesnt work where as in other he server crashes. <br> <br>I’ve pointed media.ahemahem.com to my droplet ip. Do I need to do anything else?
@talwarsaksham: The location block needs to be inside of the server block. What were the actual errors you were seeing?
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.