# Rewrite difficulty

**URL:** <https://www.ruby-forum.com/t/rewrite-difficulty/228608>\
**Category:** NGINX\
**Created:** [April 30, 2013, 4:37am UTC](https://www.ruby-forum.com/t/rewrite-difficulty/228608 "2013-04-30T04:37:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tseveendorj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tseveendorj](https://www.ruby-forum.com/u/tseveendorj)\
**Post date:** [April 30, 2013, 4:37am UTC](https://www.ruby-forum.com/t/rewrite-difficulty/228608/1 "2013-04-30T04:37:56Z")

</div>

Hello,

I have difficulty to convert apache like rewrite to nginx. This is my  
config file of virtualhost on nginx. [server { listen 80; server\_name 192.168.1.2; - Pastebin.com](http://pastebin.com/HTtKXnFy)

My installed php script should have following rewrite

> **[RewriteEngine OnRewriteCond %{REQUEST\_URI} !^/mnub2010/file/.\*RewriteCond -...](https://pastebin.com/M2h3uAt3)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Currently any requested php code displayed it’s source on browser. How  
could I migrate ?

Thanks.

---

<div class="post-metadata">

**Author:** ![tseveendorj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tseveendorj](https://www.ruby-forum.com/u/tseveendorj)\
**Post date:** [April 30, 2013, 4:01pm UTC](https://www.ruby-forum.com/t/rewrite-difficulty/228608/2 "2013-04-30T16:01:31Z")

</div>

On 30 April 2013 03:36, tseveendorj [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,
> 
> I have difficulty to convert apache like rewrite to nginx. This is my config  
> file of virtualhost on nginx. [server { listen 80; server\_name 192.168.1.2; - Pastebin.com](http://pastebin.com/HTtKXnFy)

OMFG. You win today’s prize for “Nginx config I am least likely even  
to /try/ and change”. Congrats! 😉

> My installed php script should have following rewrite  
> [RewriteEngine OnRewriteCond %{REQUEST\_URI} !^/mnub2010/file/.\*RewriteCond - Pastebin.com](http://pastebin.com/M2h3uAt3)
> 
> Currently any requested php code displayed it’s source on browser. How could  
> I migrate ?

You need to start small. Learn how Nginx does its thing in one small  
area and when you’ve understood that, move on the next.

At the moment, you have literally picked up your apache config and  
dumped it into Nginx’s config syntax. You are unlikely to succeed if  
you don’t learn how to work _with_ Nginx, instead of trying just to  
make it behave like Apache.

This may not be the “here’s your config; I fixed it” reply you were  
looking for, but it’s the best I can give you. Your Nginx config is  
/horrible/, and I’m not going to spend my time deciphering it! 🙂

Have a _really_ good read of  
[Module ngx\_http\_rewrite\_module](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite) and  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpRewriteModule). They’d be good places to  
start …

## J

Jonathan M. // Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![tseveendorj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tseveendorj](https://www.ruby-forum.com/u/tseveendorj)\
**Post date:** [August 1, 2013, 9:11am UTC](https://www.ruby-forum.com/t/rewrite-difficulty/228608/3 "2013-08-01T09:11:34Z")

</div>

Hello,

My understanding is on Apache rules like follow and convert it to nginx

If anyone request anything except follow URI /file/, /install/,  
/design/,  
/plugins/, /phpmyadmin/ then nginx will forward anything to  
/index.php?do=anything

RewriteCond %{REQUEST\_URI} !^/file/.\*  
RewriteCond %{REQUEST\_URI} !^/install/.\*  
RewriteCond %{REQUEST\_URI} !^/design/.\*  
RewriteCond %{REQUEST\_URI} !^/plugins/.\*  
RewriteCond %{REQUEST\_URI} !^/phpmyadmin/.\*  
RewriteRule ^(/.\*)$ /index.php?do=$1 [L]

nginx

location / {  
if ( $request\_uri !~  
^(/file/|/install/|/design/|/plugins/|/phpmyadmin/)) {  
rewrite ^(/.\*)$ /index.php?do=$1;  
}  
}

Is this right ? It works on my server. I’m confusing where I need to put  
this rewrite. Am I right ?

On Tue, Apr 30, 2013 at 10:01 AM, Jonathan M.  
\<removed\_email\_address@domain.invalid
