Redirect Rule

Maxim Dounin mdounin at mdounin.ru
Sat Jul 9 17:23:29 MSD 2011


Hello!

On Sat, Jul 09, 2011 at 06:19:04PM +0530, milin korath wrote:

> Hello
> 
> I am running my djago application in nginx server. In my configuration I
> redirect all http to https using the below  settings
> 
> location / { rewrite ^/(.*) https://mydomain.com/$1 permanent; }
> 
> What i want is i need to redirect to all my http request to https  except
> only one url like http://mydomain.com/x/y.
> 
> I tried
> 
> location ~* / {

There is no need to use regexp here, just normal "location /" will 
do the same thing.

>     rewrite ^/(.*) https://mydomain.com/$1 permanent;

Something like

    rewrite ^ https://mydomain.com$request_uri? permanent;

is a bit more effecient way to do the same thing.

> }
> 
> location = mydomain.com/x/y {

You don't need "mydomain.com" here, just "location = /x/y".

>     rewrite ^/(.*) http://mydomain.com/$1 permanent;

And you don't need redirect here, as it will create infinite loop 
as long as this is config for http part of mydomain.com.

> }
> 
> But no luck.Can you please advice me what went wrong here.Really i am struck
> with this.

Bringing all of the above together gives something like this:

    location / {
        rewrite ^ https://mydomain.com$request_uri? permanent;
    }

    location = /x/y {
        # ... process it right here
    }

Maxim Dounin



More information about the nginx mailing list