Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx redirect all contents of a subdirectory to another subdirectory

Let say that I have a url like this:

http://www.example.com/admin/admin.php?fail=1

how can I rewrite the url to be

http://www.example.com/another/subdirectory/admin.php?fail=1

Thank you


Update: this is what I've tried so far, but it will not redirect admin.php?fail=1

location /admin/ {
    rewrite ^/admin/(.*)$ 
    /another/subdirectory/$1 redirect;
}
like image 671
Fariz Luqman Avatar asked Aug 22 '14 12:08

Fariz Luqman


1 Answers

I rather use return 301 for redirections and use rewrite only if I want to display something like a nice url.

Please try the following

location  ~ ^/admin/(.*) {
    return 301  /another/subdirectory/$1 ;
}
like image 185
ffflabs Avatar answered Nov 15 '22 04:11

ffflabs