How to set up nested subfolder to subdomain Nginx 301 redirects -


i'm trying set nginx redirects rewrite url several older forum setups new forum. older forums ran subfolders, while current forum running subdomain of same site.

so, example, want any request site.com/ask redirected front page of forum.site.com. since i'm dealing 3 old forums, tried set nested redirect this:

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;        } } 

with above rules, first 1 works , partially. example, request site.com/ask gets redirected forum.site.com, fine, request to, say, site.com/ask/what-is-this goes forum.site.com/404.

request site.com/forum , site.com/qa not work @ all.

i'm sure there's simpler way of doing this, don't want spend several days trying figure out.

your input welcome , appreciated.

edit:

not getting anywhere above code, reduced this:

location ~ ^/\~([^/]+)/(.*)$ {             location ~ ^/\~(qa|forum|ask)/(.*)$ {                   rewrite ^/~(qa|forum|ask)/(.*)$ http://forum.site.com$1 permanent;             }     } 

but result still same. ideas?

actually want redirect user main page of forum regardless of page came to. try this.

location /qa/ {     return 301 http://forum.site.com; }  location /ask/ {     return 301 http://forum.site.com; }  location /forum/ {     return 301 http://forum.site.com; } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -