# Https rewrite for subdirectory only

**URL:** <https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955>\
**Category:** NGINX\
**Created:** [December 26, 2010, 6:20am UTC](https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955 "2010-12-26T06:20:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikuSESS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@nikuSESS](https://www.ruby-forum.com/u/nikuSESS)\
**Post date:** [December 26, 2010, 6:20am UTC](https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955/1 "2010-12-26T06:20:51Z")

</div>

Hi,

I’m a noob.

How to rewrite http to https in /admin location only ?

I put something like this in nginx.conf :  
location /admin {  
rewrite ^(.\*) https://$server\_name$1 permanent;  
}

But I always get error message “The page isn’t redirecting properly” in  
Firefox when I browse http://$server\_name/admin

Thanks.

Best regards

## Gunawan

Using Opera’s revolutionary e-mail client: [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![gunawan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/eb9ed0/32.png) [@gunawan](https://www.ruby-forum.com/u/gunawan)\
**Post date:** [December 26, 2010, 10:25am UTC](https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955/2 "2010-12-26T10:25:22Z")

</div>

On Sun, Dec 26, 2010 at 12:20 PM, gunawan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> }
> 
> But I always get error message “The page isn’t redirecting properly” in  
> Firefox when I browse http://$server\_name/admin

…how about posting the full config file you’re using.

---

<div class="post-metadata">

**Author:** ![gunawan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/eb9ed0/32.png) [@gunawan](https://www.ruby-forum.com/u/gunawan)\
**Post date:** [December 26, 2010, 11:14am UTC](https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955/3 "2010-12-26T11:14:11Z")

</div>

Attached is the nginx.conf file, no separtion between server 80 and  
server  
443.

If I make separation between server 80 and server 443, it’s ok.

Thanks.

On Sun, 26 Dec 2010 17:23:37 +0800, Edho P Arief [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > rewrite ^(.\*) https://$server\_name$1 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)

–  
Using Opera’s revolutionary e-mail client: [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![gunawan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/eb9ed0/32.png) [@gunawan](https://www.ruby-forum.com/u/gunawan)\
**Post date:** [December 26, 2010, 11:18am UTC](https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955/4 "2010-12-26T11:18:34Z")

</div>

On Sun, Dec 26, 2010 at 5:13 PM, gunawan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Attached is the nginx.conf file, no separtion between server 80 and server  
> 443.
> 
> If I make separation between server 80 and server 443, it’s ok.

That’s the problem.

Also it’s recommended to make separate block for http and https.

Here’s what happens:

1. access http://$server\_name/admin
2. matches /admin { } block, nginx redirects to  
https://$server\_name/admin
3. matches /admin { } block, nginx redirects to  
https://$server\_name/admin
4. repeat for infinity

Firefox sanely stops following redirection when it detects such loop.

tip: use

rewrite ^ https://$server\_name$request\_uri?$args permanent;

instead of

rewrite ^(.\*) https://$server\_name$1 permanent;

---

<div class="post-metadata">

**Author:** ![gunawan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/eb9ed0/32.png) [@gunawan](https://www.ruby-forum.com/u/gunawan)\
**Post date:** [December 26, 2010, 11:21am UTC](https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955/5 "2010-12-26T11:21:42Z")

</div>

Attached is the nginx.conf file, no separtion between server 80 and  
server  
443.

If I make separation between server 80 and server 443, it’s ok.

Thanks.

On Sun, 26 Dec 2010 17:23:37 +0800, Edho P Arief [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > rewrite ^(.\*) https://$server\_name$1 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)

–  
Using Opera’s revolutionary e-mail client: [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![gunawan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/eb9ed0/32.png) [@gunawan](https://www.ruby-forum.com/u/gunawan)\
**Post date:** [December 26, 2010, 3:01pm UTC](https://www.ruby-forum.com/t/https-rewrite-for-subdirectory-only/200955/6 "2010-12-26T15:01:02Z")

</div>

Ok, thanks.

On Sun, 26 Dec 2010 18:17:33 +0800, Edho P Arief [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
