4

I would like to redirect admin subdirectory to a subdomain. I tried to create this rule for Nginx however it's not working:

location ^~ /admin/ {
        rewrite ^/admin(.*) http://admin.example.com$uri permanent;
     }

Thank you Regards

7

Something like this should do the job:

location ^~ /admin/ {
    rewrite ^/admin/(.*) http://admin.example.com/$1 permanent;
}
  • 1
    Thanks for reply. I've changed a bit to optimize it: rewrite ^ http://admin.example.com/login.php$1 permanent;. I would like to also set another redirection from http://admin.exmaple.com to http://admin.example.com/login.php. Do I have to set another "location" or there is any better way to achive this. Will this cause any loops?. Thank you – HTF Jun 6 '12 at 12:29
  • 1
    You should use $scheme instead of http:// since you can later use https. rewrite ^/admin/(.*) $scheme://admin.example.com/$1 permanent; See: nginx.org/en/docs/… – darkless Mar 17 '17 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.