# Redirect Rule

**URL:** <https://www.ruby-forum.com/t/redirect-rule/209254>\
**Category:** NGINX\
**Created:** [July 9, 2011, 2:49pm UTC](https://www.ruby-forum.com/t/redirect-rule/209254 "2011-07-09T14:49:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 9, 2011, 2:49pm UTC](https://www.ruby-forum.com/t/redirect-rule/209254/1 "2011-07-09T14:49:54Z")

</div>

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](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](http://mydomain.com/x/y).

I tried

location ~\* / {  
rewrite ^/(.\*) [https://mydomain.com/$1](https://mydomain.com/$1) permanent;  
}

location = [mydomain.com/x/y](http://mydomain.com/x/y) {  
rewrite ^/(.\*) [http://mydomain.com/$1](http://mydomain.com/$1) permanent;  
}

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

Thanks

Milin Korath

---

<div class="post-metadata">

**Author:** ![milin\_korath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@milin\_korath](https://www.ruby-forum.com/u/milin_korath)\
**Post date:** [July 9, 2011, 3:23pm UTC](https://www.ruby-forum.com/t/redirect-rule/209254/2 "2011-07-09T15:23:51Z")

</div>

Hello!

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

> 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](http://mydomain.com/x/y) {

You don’t need “[mydomain.com](http://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](http://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 D.

---

<div class="post-metadata">

**Author:** ![milin\_korath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@milin\_korath](https://www.ruby-forum.com/u/milin_korath)\
**Post date:** [July 10, 2011, 11:15am UTC](https://www.ruby-forum.com/t/redirect-rule/209254/3 "2011-07-10T11:15:14Z")

</div>

Hi

---

<div class="post-metadata">

**Author:** ![milin\_korath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@milin\_korath](https://www.ruby-forum.com/u/milin_korath)\
**Post date:** [July 10, 2011, 12:11pm UTC](https://www.ruby-forum.com/t/redirect-rule/209254/4 "2011-07-10T12:11:30Z")

</div>

Hello!

On Sat, Jul 09, 2011 at 09:41:42PM +0530, milin korath wrote:

> Hi
> 
> > location = /x/y {  
> > # … process it right here  
> > }  
> > What should i need to write here.Sorry i am not familiar with nginx  
> > directives ..

If you want it to be served as static - just leave this block  
empty. If you want to handle it with backend - write appropriate  
proxy\_pass/fastcgi\_pass/… as in your https server.

Maxim D.

> > > > Hello  
> > > > I tried  
> > > > rewrite ^ https://mydomain.com$request\_uri? permanent;
> > > 
> > > * * *
> > > 
> > > nginx mailing list  
> > > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)
