# Apache to nginx rewrite rule

**URL:** <https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068>\
**Category:** NGINX\
**Created:** [December 29, 2010, 4:31pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068 "2010-12-29T16:31:38Z")\
**Posts on this page:** 7\
**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:** [December 29, 2010, 4:31pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068/1 "2010-12-29T16:31:38Z")

</div>

Looking to do something like this:

RewriteRule ^youtube/(.\*)$ [http://www.youtube.com/$1](http://www.youtube.com/$1) [L]

This the configuration I’m thinking of?

location /youtube/  
{  
rewrite ^(.\*)$ [http://www.youtube.com$1](http://www.youtube.com$1)  
}

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [December 29, 2010, 4:43pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068/2 "2010-12-29T16:43:32Z")

</div>

On 29 Dez 2010 15h30 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [1 \<multipart/alternative (7bit)\>]  
> [1.1 \<text/plain; ISO-8859-1 (7bit)\>]  
> Looking to do something like this:
> 
> RewriteRule ^youtube/(.\*)$ [http://www.youtube.com/$1](http://www.youtube.com/$1) [L]
> 
> This the configuration I’m thinking of?
> 
> location /youtube/  
> ^^^^^^^^^

This means that you have a location /youtube not a host (vhost)

> **[YouTube](https://www.youtube.com/)**
>
> Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.

> {  
> rewrite ^(.\*)$ [http://www.youtube.com$1](http://www.youtube.com$1)  
> }

You seem to be confusing host (server\_name) with location. That type  
of rewriting must be done at the server (virtual host) level.

Cf. [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Pitfalls#Server_Name)

— appa

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [December 29, 2010, 6:05pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068/3 "2010-12-29T18:05:45Z")

</div>

Thanks, but no, I’m not confusing location with host name.

I’m trying to redirect any requests on our domain as follows:

[https://www.ourdomain.com/youtube/v/mydjFYoD4WS&hl=en\_US&fs=1&rel=0&autoplay=1](https://www.ourdomain.com/youtube/v/mydjFYoD4WS&hl=en_US&fs=1&rel=0&autoplay=1)

to:

> **[\- YouTube](https://www.youtube.com/v/mydjFYoD4WS&hl=en_US&fs=1&rel=0&autoplay=1)**
>
> Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.

This is to solve a SSL warning issue. We’re already doing it on another  
site using the .htaccess rule I provided.

See: [http://www.adammershon.com/display-youtube-videos-on-ssl-page/](http://www.adammershon.com/display-youtube-videos-on-ssl-page/)

for more specific information and example.

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [December 29, 2010, 8:57pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068/4 "2010-12-29T20:57:32Z")

</div>

that worked, thanks

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [December 29, 2010, 6:22pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068/5 "2010-12-29T18:22:05Z")

</div>

On 29 Dez 2010 17h04 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This is to solve a SSL warning issue. We’re already doing it on  
> another site using the .htaccess rule I provided.
> 
> See: [http://www.adammershon.com/display-youtube-videos-on-ssl-page/](http://www.adammershon.com/display-youtube-videos-on-ssl-page/)

Try this:

location /youtube {  
rewrite ^/youtube/(.\*)$ [http://wwww.youtube.com/$1](http://wwww.youtube.com/$1) break;  
}

— appa

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [December 29, 2010, 9:00pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068/6 "2010-12-29T21:00:42Z")

</div>

On Wed, Dec 29, 2010 at 02:56:10PM -0500, Ilan B. wrote:

> that worked, thanks

You do not need “break”.

location /youtube {  
rewrite ^/youtube/(.\*)$ [http://wwww.youtube.com/$1](http://wwww.youtube.com/$1);  
}

This is enough.

> > > 
> > 
> > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

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

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [December 29, 2010, 9:16pm UTC](https://www.ruby-forum.com/t/apache-to-nginx-rewrite-rule/201068/7 "2010-12-29T21:16:59Z")

</div>

On 29 Dez 2010 19h59 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This is enough.  
> Yes. There’s no point in having a flag here, since the redirect is to  
> an external site, so no other location is tried for handling the  
> request. It exits immediately.

Thanks Igor,  
— appa
