# Rewrite problem

**URL:** <https://www.ruby-forum.com/t/rewrite-problem/195093>\
**Category:** NGINX\
**Created:** [September 16, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/rewrite-problem/195093 "2010-09-16T18:37:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [September 16, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/rewrite-problem/195093/1 "2010-09-16T18:37:59Z")

</div>

Hello,

location ~ /admin/

Above matches every admin folder on the domain but i just want to match  
“/admin” on the url like [http://domain.com/admin](http://domain.com/admin)

Tried this location = /admin/

But that did not work. I`m suing this location to password protect.

Posted at Nginx Forum:

> **[Rewrite problem](https://forum.nginx.org/read.php?2,131021,131021#msg-131021)**
>
> Hello, location ~ /admin/ Above matches every admin folder on the domain but i just want to match "/admin" on the url like http://domain.com/admin Tried this location = /admin/ But that did not work. I\`m suing this location to pa

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [September 16, 2010, 7:17pm UTC](https://www.ruby-forum.com/t/rewrite-problem/195093/2 "2010-09-16T19:17:12Z")

</div>

How to match every php file under the admin directory? Thanks. I dont  
want to match admin folder globally on the domain.

Posted at Nginx Forum:

> **[Re: Rewrite problem](https://forum.nginx.org/read.php?2,131021,131035#msg-131035)**
>
> Hello, location ~ /admin/ Above matches every admin folder on the domain but i just want to match "/admin" on the url like http://domain.com/admin Tried this location = /admin/ But that did not work. I\`m suing this location to pa

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [September 16, 2010, 7:22pm UTC](https://www.ruby-forum.com/t/rewrite-problem/195093/3 "2010-09-16T19:22:28Z")

</div>

On Thu, Sep 16, 2010 at 12:37:01PM -0400, st1905 wrote:

> Hello,
> 
> location ~ /admin/
> 
> Above matches every admin folder on the domain but i just want to match  
> “/admin” on the url like [http://domain.com/admin](http://domain.com/admin)
> 
> Tried this location = /admin/
> 
> But that did not work. I`m suing this location to password protect.

location = /admin

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [September 16, 2010, 7:27pm UTC](https://www.ruby-forum.com/t/rewrite-problem/195093/4 "2010-09-16T19:27:45Z")

</div>

Ok, solved this, just in case anyone needs the solution, here it is.

```auto
location /admin {
    auth_basic "Restricted";
    auth_basic_user_file /path/to/.htpasswd;
    location ~ \.php$ {
      include fastcgi.conf;
      fastcgi_pass my-backend;
    }
  }

```

Posted at Nginx Forum:

> **[Re: Rewrite problem](https://forum.nginx.org/read.php?2,131021,131044#msg-131044)**
>
> Hello, location ~ /admin/ Above matches every admin folder on the domain but i just want to match "/admin" on the url like http://domain.com/admin Tried this location = /admin/ But that did not work. I\`m suing this location to pa

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [September 16, 2010, 7:23pm UTC](https://www.ruby-forum.com/t/rewrite-problem/195093/5 "2010-09-16T19:23:04Z")

</div>

On Thu, Sep 16, 2010 at 01:15:45PM -0400, st1905 wrote:

> How to match every php file under the admin directory? Thanks. I dont  
> want to match admin folder globally on the domain.

location ~ ^/admin/.+.php$

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [September 18, 2010, 6:56pm UTC](https://www.ruby-forum.com/t/rewrite-problem/195093/6 "2010-09-18T18:56:35Z")

</div>

## Igor S. Wrote:

> –  
> Igor S.  
> [Igor Sysoev](http://sysoev.ru/en/)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

That worked great, thank you.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,131021,131767#msg-131767](http://forum.nginx.org/read.php?2,131021,131767#msg-131767)
