# Converting apache rewrites to nginx

**URL:** <https://www.ruby-forum.com/t/converting-apache-rewrites-to-nginx/156883>\
**Category:** NGINX\
**Created:** [January 4, 2009, 9:09pm UTC](https://www.ruby-forum.com/t/converting-apache-rewrites-to-nginx/156883 "2009-01-04T21:09:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Thornton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Andrew\_Thornton](https://www.ruby-forum.com/u/Andrew_Thornton)\
**Post date:** [January 4, 2009, 9:09pm UTC](https://www.ruby-forum.com/t/converting-apache-rewrites-to-nginx/156883/1 "2009-01-04T21:09:03Z")

</div>

Hello,

I am currently trying to get a deployment ready in an attempt to migrate  
my  
wiki from apache to nginx and php-fpm. Things have gone pretty smoothly  
so  
far, but I am having a real problem with rewrite rules. Here is what is  
currently in my apache config for a rewrite:

\<Directory “/var/www/ws/wiki”\>  
RewriteEngine On  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteRule ^(._)$ /index.php?title=$1 [PT,L,QSA]  
RewriteRule ^(images|skins)/(._)$ [http://images.testsite.com/$1/$2](http://images.testsite.com/$1/$2) [L]

I have tried adding this a couple of different ways into the nginx  
config  
file but it isn’t working. Can someone give me a hand with this? Also,  
where  
can I find docs on the rewrite functionality within nginx?

I appreciate any and all help,

Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_Thornton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Andrew\_Thornton](https://www.ruby-forum.com/u/Andrew_Thornton)\
**Post date:** [January 4, 2009, 9:37pm UTC](https://www.ruby-forum.com/t/converting-apache-rewrites-to-nginx/156883/2 "2009-01-04T21:37:21Z")

</div>

See [http://wiki.codemongers.com/NginxHttpRewriteModule](http://wiki.codemongers.com/NginxHttpRewriteModule).

Assuming your doc root is /var/www/ws, try

location /wiki/ {

if (!-e $request\_filename) {

rewrite ^/(.\*)$ /index.php?title=$1 last;

}

rewrite ^/(images|skins)/(.\*)$ [http://images.testsite.com/$1/$2](http://images.testsite.com/$1/$2) last;

}

You may need to add a forward slash in front of http in the second line.

Good luck,

Jim

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of  
Andrew Thornton  
Sent: Sunday, January 04, 2009 3:01 PM  
To: removed\_email\_address@domain.invalid  
Subject: converting apache rewrites to nginx

Hello,

I am currently trying to get a deployment ready in an attempt to migrate  
my  
wiki from apache to nginx and php-fpm. Things have gone pretty smoothly  
so  
far, but I am having a real problem with rewrite rules. Here is what is  
currently in my apache config for a rewrite:

\<Directory “/var/www/ws/wiki”\>  
RewriteEngine On  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteRule ^(._)$ /index.php?title=$1 [PT,L,QSA]  
RewriteRule ^(images|skins)/(._)$ [http://images.testsite.com/$1/$2](http://images.testsite.com/$1/$2) [L]

I have tried adding this a couple of different ways into the nginx  
config  
file but it isn’t working. Can someone give me a hand with this? Also,  
where  
can I find docs on the rewrite functionality within nginx?

I appreciate any and all help,

Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_Thornton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Andrew\_Thornton](https://www.ruby-forum.com/u/Andrew_Thornton)\
**Post date:** [January 4, 2009, 10:48pm UTC](https://www.ruby-forum.com/t/converting-apache-rewrites-to-nginx/156883/3 "2009-01-04T22:48:30Z")

</div>

Hey Jim,

Thanks for the link and for the advice. It worked great.

Thanks again
