# Redirect loop fixed, I need a better rule format

**URL:** <https://www.ruby-forum.com/t/redirect-loop-fixed-i-need-a-better-rule-format/238197>\
**Category:** NGINX\
**Created:** [December 23, 2013, 7:14am UTC](https://www.ruby-forum.com/t/redirect-loop-fixed-i-need-a-better-rule-format/238197 "2013-12-23T07:14:03Z")\
**Posts on this page:** 1\
**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:** [December 23, 2013, 7:14am UTC](https://www.ruby-forum.com/t/redirect-loop-fixed-i-need-a-better-rule-format/238197/1 "2013-12-23T07:14:03Z")

</div>

Hello everyone,

I have a little problem on hand, related to redirect loop for a specific  
location:  
server {  
listen 192.168.1.2:443 spdy ssl default\_server;  
…  
location ^~ /alpha {  
return 301 https://www.domain.com$request\_uri;  
}  
…  
}  
I would like to redirect URL’s of this format:  
[https://www.domain.com/alpha/delta/](https://www.domain.com/alpha/delta/)[more of $request\_uri]  
To:  
[https://www.domain.com/delta/](https://www.domain.com/delta/)[more of $request\_uri]

I can access fine the [https://www.domain.com/delta/](https://www.domain.com/delta/)… directory. When  
the  
GET is performed on [https://www.domain.com/alpha/](https://www.domain.com/alpha/), it tries to use the  
old  
REQUEST URI which is obviously wrong. I solved the issue this way:  
location ^~ /alpha {  
location /alpha {  
return 301 [https://www.domain.com/](https://www.domain.com/);  
}  
location ~ ^/alpha/(.+)$ {  
return 301 [https://www.domain.com/$1](https://www.domain.com/$1);  
}  
}

Is there a better (more compact) way to achieve the same results?  
With the rules listed above, I tell Nginx to redirect /alpha or /alpha/  
to  
/.  
If the $request\_uri contains something after /alpha, I grab the part of  
$request\_uri after /alpha and push it to /.

Thank you for helping me make this configuration part better.

Posted at Nginx Forum:

> **[Redirect loop fixed, I need a better rule format](https://forum.nginx.org/read.php?2,245780,245780#msg-245780)**
>
> Hello everyone, I have a little problem on hand, related to redirect loop for a specific location: server { listen 192.168.1.2:443 spdy ssl default\_server; ... location ^~ /alpha { return 301 https://www.domain.com$request\_uri; } ..
