By finid
I’m trying to set up multiple subfolder to subdomain redirect like this:
<pre>
location ~ ^/~([^/]+)/(.)$ {
location ~ ^/~ask/(.)$ {
rewrite ^(.*)$ http://forum.site.com$1 permanent;
}
location ~ ^/~forum/(.)$ {
rewrite ^(.)$ http://forum.site.com$1 permanent;
}
location ~ ^/~qa/(.)$ {
rewrite ^(.)$ http://forum.site.com$1 permanent;
}
}
</pre>
The idea is that all requests to site.com/ask, site.com/forum and site.com/qa will be redirected to forum.site.com. With the above code, only redirects from site.com/ask are working. What could be wrong with the rest and is there a better way to setting them up?
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!
How would you modify the location line to match, or is that not needed with your form of the rewrite?
That’s not needed – you can replace all of the location blocks with the one rewrite rule I posted.
Try using the following rewrite rule instead, does that fix it? <br><pre>rewrite ^/(ask|forum|qa)/(.*)$ http://forum.site.com/$2 permanent;</pre>
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.