# Targeting homepage (not sub pages/dirs/)

**URL:** <https://www.ruby-forum.com/t/targeting-homepage-not-sub-pages-dirs/238576>\
**Category:** NGINX\
**Created:** [January 17, 2014, 6:42pm UTC](https://www.ruby-forum.com/t/targeting-homepage-not-sub-pages-dirs/238576 "2014-01-17T18:42:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [January 17, 2014, 6:42pm UTC](https://www.ruby-forum.com/t/targeting-homepage-not-sub-pages-dirs/238576/1 "2014-01-17T18:42:06Z")

</div>

What should I add to this directive to target also the home page (root  
of  
the website, e.g. [website.com](http://website.com))?  
I already have ‘index.php’ in the directive but what if I visit  
[website.com](http://website.com)(without /index.php)?

if ($request\_uri ~\*  
“(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.\*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]±sitemap([0-9]+)?.xml)”)

# I think I need to add another if, this time not with ~\* though but with

Something like

if ($request\_uri = “(/)”)

…?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![lorenzo\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lorenzo\_r](https://www.ruby-forum.com/u/lorenzo_r)\
**Post date:** [January 17, 2014, 7:30pm UTC](https://www.ruby-forum.com/t/targeting-homepage-not-sub-pages-dirs/238576/2 "2014-01-17T19:30:51Z")

</div>

On Fri, Jan 17, 2014 at 06:40:37PM +0100, Lorenzo R. wrote:

Hi there,

> What should I add to this directive to target also the home page (root of  
> the website, e.g. [website.com](http://website.com))?

I’d suggest

location = / {}

as being simplest.

But if you want it to be part of the already-present regex, then you  
want to match either “exactly /” or “starts with /?”.

“exactly” is “start of string, /, end of string”.

“starts with” is “start of string, /, ?”.

Check your regex manual for which bits need to be escaped and which bits  
mean “start” and “end”.

Good luck with it,

## f

Francis D. removed\_email\_address@domain.invalid
