# Simple rewrite (redirection)

**URL:** <https://www.ruby-forum.com/t/simple-rewrite-redirection/214174>\
**Category:** NGINX\
**Created:** [November 23, 2011, 8:47pm UTC](https://www.ruby-forum.com/t/simple-rewrite-redirection/214174 "2011-11-23T20:47:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [November 23, 2011, 8:47pm UTC](https://www.ruby-forum.com/t/simple-rewrite-redirection/214174/1 "2011-11-23T20:47:00Z")

</div>

Hi Guys,

In my HTTP config section in the config file, I would like to implement  
a redirection based on this scenario:

If the URL is not “[http://sitea.com/exactmatch](http://sitea.com/exactmatch)” then redirect to the  
“https” home. else go to our hidden url (our testing boxes)

#logic would be somthing like this…  
If (The URL is anything but “/ahiddenurl”)  
{  
go to “[https://sitea.com](https://sitea.com)”  
}  
else  
{  
go to “[http://hiddenurl](http://hiddenurl)”  
}

Is this possible in the nginx.conf file?? Any help would be so very much  
appreciated!

Posted at Nginx Forum:

> **[Simple rewrite (redirection)](https://forum.nginx.org/read.php?2,218893,218893#msg-218893)**
>
> Hi Guys, In my HTTP config section in the config file, I would like to implement a redirection based on this scenario: If the URL is not "http://sitea.com/exactmatch" then redirect to the "https" home. else go to our hidden url...

---

<div class="post-metadata">

**Author:** ![EricTheRed03](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c4cdca/32.png) [@EricTheRed03](https://www.ruby-forum.com/u/EricTheRed03)\
**Post date:** [November 23, 2011, 8:54pm UTC](https://www.ruby-forum.com/t/simple-rewrite-redirection/214174/2 "2011-11-23T20:54:30Z")

</div>

This is the block of code I’ve been working on for hours … ☹

--------------- nginx.conf ------------  
server {  
listen 80;  
server\_name [sitea.com](http://sitea.com);  
rewrite ^(/hiddendevpath)(._)$ [http://sitea.com/](http://sitea.com/) ;  
rewrite ^(._) [https://sitea.com](https://sitea.com)  
}

------------- testing below ----------

sudo /usr/sbin/nginx -t  
Error: nginx: [emerg] invalid number of arguments in “rewrite” directive  
in /etc/nginx/nginx.conf:44

Posted at Nginx Forum:

> **[Re: Simple rewrite (redirection)](https://forum.nginx.org/read.php?2,218893,218894#msg-218894)**
>
> Hi Guys, In my HTTP config section in the config file, I would like to implement a redirection based on this scenario: If the URL is not "http://sitea.com/exactmatch" then redirect to the "https" home. else go to our hidden url...

---

<div class="post-metadata">

**Author:** ![EricTheRed03](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c4cdca/32.png) [@EricTheRed03](https://www.ruby-forum.com/u/EricTheRed03)\
**Post date:** [November 23, 2011, 9:18pm UTC](https://www.ruby-forum.com/t/simple-rewrite-redirection/214174/3 "2011-11-23T21:18:12Z")

</div>

On Wednesday 23 November 2011 23:54:06 EricTheRed03 wrote:

> ------------- testing below ----------
> 
> sudo /usr/sbin/nginx -t  
> Error: nginx: [emerg] invalid number of arguments in “rewrite” directive  
> in /etc/nginx/nginx.conf:44

You forgot a ; at the end of this directive:  
rewrite ^(.\*) [https://sitea.com](https://sitea.com)

Try this:

server {

```
listen 80;
server_name sitea.com;

location /hiddendevpath {
  rewrite ^ https://sitea.com/;
}

```

}

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![EricTheRed03](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c4cdca/32.png) [@EricTheRed03](https://www.ruby-forum.com/u/EricTheRed03)\
**Post date:** [November 24, 2011, 11:08am UTC](https://www.ruby-forum.com/t/simple-rewrite-redirection/214174/4 "2011-11-24T11:08:11Z")

</div>

On Wed, Nov 23, 2011 at 02:46:13PM -0500, EricTheRed03 wrote:

> {  
> go to “[https://sitea.com](https://sitea.com)”  
> }  
> else  
> {  
> go to “[http://hiddenurl](http://hiddenurl)”  
> }
> 
> Is this possible in the nginx.conf file?? Any help would be so very much  
> appreciated!

server {  
listen 80;  
server\_name [sitea.com](http://sitea.com);

```
location / {
    return https://sitea.com;
}

location /hiddenurl {
    ...
}

```

}

–  
Igor S.
