# How to change apache .htaccess to nginx rewrite

**URL:** <https://www.ruby-forum.com/t/how-to-change-apache-htaccess-to-nginx-rewrite/118001>\
**Category:** NGINX\
**Created:** [October 23, 2007, 10:40am UTC](https://www.ruby-forum.com/t/how-to-change-apache-htaccess-to-nginx-rewrite/118001 "2007-10-23T10:40:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba9def/32.png) [@liyu](https://www.ruby-forum.com/u/liyu)\
**Post date:** [October 23, 2007, 10:40am UTC](https://www.ruby-forum.com/t/how-to-change-apache-htaccess-to-nginx-rewrite/118001/1 "2007-10-23T10:40:43Z")

</div>

apache .htaccess  
RewriteRule ^newposts(/?)+$ index.php?subaction=newposts [L]  
RewriteRule ^newposts/page/([0-9]+)(/?)+$  
index.php?subaction=newposts&cstart=$1 [L]  
RewriteRule ^static/(.\*).html(/?)+$ index.php?do=static&page=$1 [L]  
RewriteRule ^favorites(/?)+$ index.php?do=favorites [L]  
RewriteRule ^favorites/page/([0-9]+)(/?)+$  
index.php?do=favorites&cstart=$1 [L]  
RewriteRule ^statistics.html$ index.php?do=stats [L]  
RewriteRule ^addnews.html$ index.php?do=addnews [L]  
RewriteRule ^rss.xml$ engine/rss.php [L]  
RewriteRule ^sitemap.xml$ uploads/sitemap.xml [L]  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteRule ^([^.]+)/page/([0-9]+)(/?)+$  
index.php?do=cat&category=$1&cstart=$2 [L]  
RewriteRule ^([^.]+)/?$ index.php?do=cat&category=$1 [L]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^([^\<]+)/rss.xml$ engine/rss.php?do=cat&category=$1 [L]  
RewriteRule ^page,([0-9]+),([^/]+).html$  
index.php?do=static&page=$2&news\_page=$1 [L]  
RewriteRule ^([^/]+).html$ index.php?do=static&page=$1 [L]

---

<div class="post-metadata">

**Author:** ![liyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba9def/32.png) [@liyu](https://www.ruby-forum.com/u/liyu)\
**Post date:** [October 23, 2007, 11:16am UTC](https://www.ruby-forum.com/t/how-to-change-apache-htaccess-to-nginx-rewrite/118001/2 "2007-10-23T11:16:59Z")

</div>

Did you make any effort to find out by your self or did you just  
dumped some old configuration in hope of a ready made answer?

RewriteRule ^newposts(/?)+$ index.php?subaction=newposts [L]  
rewrite ^/newposts.\*$ /index.php?subaction=newposts last;

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

Li Yu kirjoitti 23.10.2007 kello 11:40:

---

<div class="post-metadata">

**Author:** ![liyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba9def/32.png) [@liyu](https://www.ruby-forum.com/u/liyu)\
**Post date:** [October 23, 2007, 11:21am UTC](https://www.ruby-forum.com/t/how-to-change-apache-htaccess-to-nginx-rewrite/118001/3 "2007-10-23T11:21:06Z")

</div>

On Tue, Oct 23, 2007 at 12:07:51PM +0300, Riku R?is?nen wrote:

> Did you make any effort to find out by your self or did you just  
> dumped some old configuration in hope of a ready made answer?
> 
> RewriteRule ^newposts(/?)+$ index.php?subaction=newposts [L]  
> rewrite ^/newposts.\*$ /index.php?subaction=newposts last;

The arguments are depend on .htaccess’s location.  
If .htaccess is in /dir/ then the rule should probably be:

rewrite ^/dir/newposts.\*$ /dir/index.php?subaction=newposts last;

---

<div class="post-metadata">

**Author:** ![liyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba9def/32.png) [@liyu](https://www.ruby-forum.com/u/liyu)\
**Post date:** [October 23, 2007, 11:53am UTC](https://www.ruby-forum.com/t/how-to-change-apache-htaccess-to-nginx-rewrite/118001/4 "2007-10-23T11:53:23Z")

</div>

Igor S. escribiÃ³:

> The arguments are depend on .htaccess’s location.  
> If .htaccess is in /dir/ then the rule should probably be:
> 
> rewrite ^/dir/newposts.\*$ /dir/index.php?subaction=newposts last;

yes, you have to take care the .htaccess rewrite rules are relative to  
the web path they are and with nginx you are in the config file so they  
have to be considered absolute.
