# How to change Root URL

**URL:** <https://www.ruby-forum.com/t/how-to-change-root-url/205066>\
**Category:** NGINX\
**Created:** [March 28, 2011, 9:19pm UTC](https://www.ruby-forum.com/t/how-to-change-root-url/205066 "2011-03-28T21:19:31Z")\
**Posts on this page:** 2\
**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:** [March 28, 2011, 9:19pm UTC](https://www.ruby-forum.com/t/how-to-change-root-url/205066/1 "2011-03-28T21:19:31Z")

</div>

Hi,

I am new to nginx.

How can I change my URL from lets say  
[http://ip:80/sample/chap1/demo.jspto](http://ip:80/sample/chap1/demo.jspto)  
[http://ip:80/\*test/\*sample/chap1/demo.jsp](http://ip:80/*test/*sample/chap1/demo.jsp) { pl note the path test  
between  
IP:port and sample)

rgds,

---

<div class="post-metadata">

**Author:** ![Mohammed\_Ashraf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecccb3/32.png) [@Mohammed\_Ashraf](https://www.ruby-forum.com/u/Mohammed_Ashraf)\
**Post date:** [March 28, 2011, 11:57pm UTC](https://www.ruby-forum.com/t/how-to-change-root-url/205066/2 "2011-03-28T23:57:40Z")

</div>

On Tue, Mar 29, 2011 at 12:48:56AM +0530, Mohammed Ashraf wrote:

Hi there,

> I am new to nginx.

Welcome. There’s lots of good information at [http://nginx.org/](http://nginx.org/) and  
[http://wiki.nginx.org/](http://wiki.nginx.org/) – you can check there to understand what the  
suggested configuration will do.

> How can I change my URL from lets say [http://ip:80/sample/chap1/demo.jspto](http://ip:80/sample/chap1/demo.jspto)  
> [http://ip:80/\*test/\*sample/chap1/demo.jsp](http://ip:80/*test/*sample/chap1/demo.jsp) { pl note the path test between  
> IP:port and sample)

I’d use a rewrite in the nginx config file, so when someone requests  
/url, they are invited to instead request /new/url; and when they  
request /new/url, they are given the content from the new directory.

Combining this example with the question in the Subject: line, I  
suggest:

location / {  
rewrite ^ /test$request\_uri? permanent;  
}

location /test/ {  
}

See, for example, [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpRewriteModule#rewrite)  
for what the rewrite directive does; and  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#location) for how the location  
blocks  
are matched.

Depending on what else you want the server to do, you will want more  
location blocks; and you may want to add “^~” to one of the above  
locations.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
