nginx folder redirect

7,644

Solution 1

location / {

  rewrite ^\/path1\/(.*)$ http://sub.domain.com/$1 last;

  // rest of config for root

}

I'm from an Apache background and I've just started using Nginx in earnest, I've struggled with the re-writes myself, but, I've used the above recently without apparent issue.

Solution 2

location = /path1 {
  rewrite ^ http://sub.domain.com$uri permanent;
}
location /path1/ {
  rewrite ^ http://sub.domain.com$uri?$args permanent;
}

edit: also read this for information on last/break/permanent/redirect.

Share:
7,644

Related videos on Youtube

Shaggy
Author by

Shaggy

Updated on September 17, 2022

Comments

  • Shaggy
    Shaggy over 1 year

    I Have a query with Two Select Clause combines with UNION.I want to select only top first row. How can i do that Using Union ?

    Select Fault,OccurredOn From ATMStatus Where Ticket=189703 // This Will retrieve single record as the primary key is applied
    Union 
    Select Fault,OccurredOn From ATMStatusHistory Where Resolved=0 AND Ticket=189703 Order By OccurredOn Desc
    
  • user36532
    user36532 about 14 years
    Accomplishes the same thing, thanks. Though I changed the rewrite to: rewrite ^\/path1\/(.*)$ sub.domain.com/path1/$1 break; Not sure of the difference between last and break yet. Something to do with a limit of 10 options when using location? I'm just recalling other documentation from memory here. Thanks!
  • Shaggy
    Shaggy almost 12 years
    Invalid Column name OccuredOn
  • Damien_The_Unbeliever
    Damien_The_Unbeliever almost 12 years
    Which row (1 or 2) is returned is, of course, not defined in this query.
  • James L.
    James L. almost 12 years
    You're right -- fixed. I'd edit it to include the OP query too, but then it would look like I just copied the answer from 'juergen d'...
  • juergen d
    juergen d almost 12 years
    This is very odd. See this simplified example