By jchud13
I have a main domain and a subdomain. I want all traffic to redirect to my subdomain. I have been trying to use return 301 and also rewrite in my nginx.conf for my default domain, but every time I do instead of the url being replaced with my subdomain; the subdomain is added on to the end of the url.
For example: rewrite ^/(.*)$ https://domain2.com/$1 permanent; is the rewrite command I am using and when I type in my domain the url becomes https://domain1.com/domain2.com/domain2.com/domain2.com forever and ever until I get the 414 request.
Any idea what is going on?
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!
Instead of using a rewrite rule you can instead use the following server declaration in your nginx.conf to make it cleaner and simpler:
server {
server_name example.com;
return 301 $scheme://subdomain.example.com$request_uri;
}
Or redirect one domain to another domain:
server {
server_name domain1.com;
return 301 $scheme://domain2.com$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.