# How to convert apache to nginx rewrite?

**URL:** <https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393>\
**Category:** NGINX\
**Created:** [October 31, 2010, 10:56am UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393 "2010-10-31T10:56:22Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [October 31, 2010, 10:56am UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/1 "2010-10-31T10:56:22Z")

</div>

Its rewrite for phpBB mod - [przemo.org](http://przemo.org).

[code]RewriteEngine on

#RewriteBase /forum

RewriteRule ^cat([0-9]\*).htm$ ./index.php?c=$1 [L,QSA]

# 

RewriteRule ^(forum|._-vf)([0-9]+)-([0-9]+),([0-9]+).htm$  
./viewforum.php?f=$2&topicdays=$3&start=$4 [L,QSA]  
RewriteRule ^(forum|._-vf)([0-9]+),([0-9]+).htm$  
./viewforum.php?f=$2&start=$3 [L,QSA]  
RewriteRule ^(forum|.\*-vf)([0-9]+).htm$ ./viewforum.php?f=$2 [L,QSA]

RewriteRule ^prev\_topic/([0-9]+).htm$  
./viewtopic.php?t=$1&view=previous [L,QSA]  
RewriteRule ^next\_topic/([0-9]+).htm$ ./viewtopic.php?t=$1&view=next  
[L,QSA]

# 

# 

RewriteRule  
^(topics[0-9]_/)?(._-vt)?([0-9]+)-([0-9]+)-([a-zA-Z]+),([0-9]+).htm$  
./viewtopic.php?t=$3&postdays=$4&postorder=$5&start=$6 [L,QSA]  
RewriteRule  
^(topics[0-9]_/)?(._-vt)?([0-9]+)-([0-9]+)-([a-zA-Z]+)-([a-zA-Z0-9]+),([0-9]+).htm$  
./viewtopic.php?t=$3&start=$7&postdays=$4&postorder=$5&highlight=$6  
[L,QSA]

# 

RewriteRule ^(topics[0-9]_/)?(._-vt)?([0-9]+),([0-9]+).htm$  
./viewtopic.php?t=$3&start=$4 [L,QSA]  
RewriteRule ^(topics[0-9]_/)?(._-vt)?([0-9]+).htm$ ./viewtopic.php?t=$3  
[L,QSA]  
RewriteRule ^postlink/([0-9]+).htm$ ./viewtopic.php?p=$1 [L,QSA]

RewriteRule ^search.htm/authors/(.+),([0-9]+)$  
./search.php?search\_author=$1&start=$2 [L,QSA]

# 

RewriteRule ^search.htm/([0-9a-z]+),([0-9]+)$  
./search.php?search\_id=$1&start=$2 [L,QSA]  
RewriteRule ^search.htm/([0-9a-z]+)$ ./search.php?search\_id=$1 [L,QSA]

# 

# 

RewriteRule ^members/([a-z]+)\_([a-z]\*)-([A-Za-z]+),([0-9]+).htm$  
./memberlist.php?letter=$2&mode=$1&order=$3&start=$4 [L,QSA]  
RewriteRule ^members(.htm|/?)$ ./memberlist.php [L,QSA]

RewriteRule ^profiles/([0-9]+).htm$ ./profile.php?mode=viewprofile&u=$1  
[L,QSA]

RewriteRule ^groups/?([0-9]\*)(.htm)?$ ./groupcp.php?g=$1 [L,QSA]  
RewriteRule ^groups/?$ ./groupcp.php [L,QSA]

# 

RewriteRule ^sitemap,([0-9]+).htm$ ./sitemap.php?offset=$1 [L,QSA]

RewriteRule ^topics([0-9]+)/?$ ./viewforum.php?f=$1.htm [L,QSA]  
RewriteRule ^(topics|postlink|prev\_topic|next\_topic)/?$ ./index.php  
[L,QSA]  
RewriteRule ^profiles/?$ ./memberlist.php [L,QSA]

#htm to php  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} (._).htm  
RewriteRule ^(.+).htm(?._)? $1.php$2 [E=WasHTML:yes]  
RewriteCond %{ENV:WasHTML} ^yes$  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.+).php(?.\*)? $1.htm$2  
[/code]

Can anybody help me to translate this to nginx rewrite?

Posted at Nginx Forum:

> **[How to convert apache to nginx rewrite?](https://forum.nginx.org/read.php?2,146186,146186#msg-146186)**
>
> Its rewrite for phpBB mod - przemo.org. \[code\]RewriteEngine on #RewriteBase /forum RewriteRule ^cat(\[0-9\]\*)\\.htm$ ./index.php?c=$1 \[L,QSA\] # RewriteRule ^(forum|.\*-vf)(\[0-9\]+)-(\[0-9\]+),(\[0-9\]+)\\.htm$ ./viewforum.php?f=$2&topicdays=$3&am

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [October 31, 2010, 12:53pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/2 "2010-10-31T12:53:36Z")

</div>

Its easy e.g the first one is  
rewrite ^cat([0-9]\*).htm$ index.php?c=$1;

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [October 31, 2010, 1:53pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/3 "2010-10-31T13:53:50Z")

</div>

I think something using try\_files but I dont really understand the  
rewritecond

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [October 31, 2010, 1:41pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/4 "2010-10-31T13:41:55Z")

</div>

Okay…

`rewrite ^/cat([0-9]*)\.htm$ index.php?c=$1;
rewrite ^/(forum|.*-vf)([0-9]+)-([0-9]+),([0-9]+)\.htm$
viewforum.php?f=$2&topicdays=$3&start=$4;
rewrite ^/(forum|.*-vf)([0-9]+),([0-9]+)\.htm$
viewforum.php?f=$2&start=$3;
rewrite ^/(forum|.*-vf)([0-9]+)\.htm$ viewforum.php?f=$2;
rewrite ^/prev_topic/([0-9]+)\.htm$ viewtopic.php?t=$1&view=previous;
rewrite ^/next_topic/([0-9]+)\.htm$ viewtopic.php?t=$1&view=next;
rewrite
^/(topics[0-9]*/)?(.*-vt)?([0-9]+)-([0-9]+)-([a-zA-Z]+),([0-9]+)\.htm$
viewtopic.php?t=$3&postdays=$4&postorder=$5&start=$6;
rewrite
^/(topics[0-9]*/)?(.*-vt)?([0-9]+)-([0-9]+)-([a-zA-Z]+)-([a-zA-Z0-9]+),([0-9]+)\.htm$
viewtopic.php?t=$3&start=$7&postdays=$4&postorder=$5&highlight=$6;
rewrite ^/(topics[0-9]*/)?(.*-vt)?([0-9]+),([0-9]+)\.htm$
viewtopic.php?t=$3&start=$4;
rewrite ^/(topics[0-9]*/)?(.*-vt)?([0-9]+)\.htm$ viewtopic.php?t=$3;
rewrite ^/postlink/([0-9]+)\.htm$ viewtopic.php?p=$1;
rewrite ^/search\.htm/authors/(.+),([0-9]+)$
search.php?search_author=$1&start=$2;
rewrite ^/search\.htm/([0-9a-z]+),([0-9]+)$
search.php?search_id=$1&start=$2;
rewrite ^/search\.htm/([0-9a-z]+)$ search.php?search_id=$1;
rewrite ^/members/([a-z]+)_([a-z]*)-([A-Za-z]+),([0-9]+)\.htm$
memberlist.php?letter=$2&mode=$1&order=$3&start=$4;
rewrite ^/members(\.htm|/?)$ memberlist.php;
rewrite ^/profiles/([0-9]+)\.htm$ profile.php?mode=viewprofile&u=$1;
rewrite ^/groups/?([0-9]*)(\.htm)?$ groupcp.php?g=$1;
rewrite ^/groups/?$ groupcp.php;
rewrite ^/sitemap,([0-9]+)\.htm$ sitemap.php?offset=$1;
rewrite ^/topics([0-9]+)/?$ viewforum.php?f=$1.htm;
rewrite ^/(topics|postlink|prev_topic|next_topic)/?$ index.php;
rewrite ^/profiles/?$ memberlist.php;
rewrite ^/(.+)\.htm(\?.*)? /$1.php$2;
rewrite ^/(.+)\.php(\?.*)? /$1.htm$2;
`

But I dont know how translate RewriteCond?

And this rewrite dont working in 100%.  
[http://www.landwirtschafts.net/cat4.htm](http://www.landwirtschafts.net/cat4.htm) - working  
[http://www.landwirtschafts.net/portal.htm](http://www.landwirtschafts.net/portal.htm) - dont working  
[http://www.landwirtschafts.net/index.htm](http://www.landwirtschafts.net/index.htm) - dont working  
[http://www.landwirtschafts.net/members.htm](http://www.landwirtschafts.net/members.htm) - dont working

How to fix it?

Posted at Nginx Forum:

> **[Re: How to convert apache to nginx rewrite?](https://forum.nginx.org/read.php?2,146186,146228#msg-146228)**
>
> Its rewrite for phpBB mod - przemo.org. \[code\]RewriteEngine on #RewriteBase /forum RewriteRule ^cat(\[0-9\]\*)\\.htm$ ./index.php?c=$1 \[L,QSA\] # RewriteRule ^(forum|.\*-vf)(\[0-9\]+)-(\[0-9\]+),(\[0-9\]+)\\.htm$ ./viewforum.php?f=$2&topicdays=$3&am

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [October 31, 2010, 3:09pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/5 "2010-10-31T15:09:06Z")

</div>

Anybody help?

Posted at Nginx Forum:

> **[Re: How to convert apache to nginx rewrite?](https://forum.nginx.org/read.php?2,146186,146251#msg-146251)**
>
> Its rewrite for phpBB mod - przemo.org. \[code\]RewriteEngine on #RewriteBase /forum RewriteRule ^cat(\[0-9\]\*)\\.htm$ ./index.php?c=$1 \[L,QSA\] # RewriteRule ^(forum|.\*-vf)(\[0-9\]+)-(\[0-9\]+),(\[0-9\]+)\\.htm$ ./viewforum.php?f=$2&topicdays=$3&am

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 1, 2010, 12:46pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/6 "2010-11-01T12:46:36Z")

</div>

Anybody can help? Please…

Posted at Nginx Forum:

> **[Re: How to convert apache to nginx rewrite?](https://forum.nginx.org/read.php?2,146186,146517#msg-146517)**
>
> Its rewrite for phpBB mod - przemo.org. \[code\]RewriteEngine on #RewriteBase /forum RewriteRule ^cat(\[0-9\]\*)\\.htm$ ./index.php?c=$1 \[L,QSA\] # RewriteRule ^(forum|.\*-vf)(\[0-9\]+)-(\[0-9\]+),(\[0-9\]+)\\.htm$ ./viewforum.php?f=$2&topicdays=$3&am

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 1, 2010, 1:08pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/7 "2010-11-01T13:08:00Z")

</div>

On Mon, Nov 1, 2010 at 6:44 PM, dong [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anybody can help? Please…

maybe you can try helping yourself by reading these…

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

> **[Regular Expression Tutorial - Learn How to Use Regular Expressions](https://www.regular-expressions.info/tutorial.html)**
>
> This tutorial teaches you how to create your own regular expressions, starting with the most basic regex concepts and ending with the most advanced and specialized capabilities.

as your particular problem is not too interesting and requires  
extensive testing from your web application itself.

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 1, 2010, 3:57pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/8 "2010-11-01T15:57:06Z")

</div>

I think,  
apache rewrite module is used heavily in many php based websites,  
so,  
nginx developers should make it easy to convert apache rewrite rules  
so that people can swtich to nginx more easily.

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 1, 2010, 4:29pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/9 "2010-11-01T16:29:47Z")

</div>

I agree. Listening in on this mailing list, I constantly hear of  
requests to  
convert an apache setup to nginx.

Having a tool to capture 80% of the easy Apache configs might be really  
helpful for folks. I realize this is a hard problem, so this is not said  
lightly.

Perhaps a future Google Summer of Code project?

-peter

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 1, 2010, 5:20pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/10 "2010-11-01T17:20:03Z")

</div>

On 11/1/10 11:27 AM, Peter Portante wrote:

> I agree. Listening in on this mailing list, I constantly hear of requests to  
> convert an apache setup to nginx.
> 
> Having a tool to capture 80% of the easy Apache configs might be really  
> helpful for folks. I realize this is a hard problem, so this is not said  
> lightly.
> 
> Perhaps a future Google Summer of Code project?
> 
> -peter

95% or more are so simple that it would be a waste of time and effort.

Top posting because that’s where the insertion point is, is like  
shitting in your pants because that’s where your asshole is.

> On 11/1/10 10:48 AM, "bvidinli"[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I think,  
> > apache rewrite module is used heavily in many php based websites,  
> > so,  
> > nginx developers should make it easy to convert apache rewrite rules  
> > so that people can swtich to nginx more easily.

It is easy most of the time. Igor writes nginx for his employer and it  
is released to the public through their kindness. He and Maxim and the  
other more expert users and those knowledgeable with the code post to  
this list in their free time and provide that support for free.  
Generally if one asks a reasonable question and shows that they have  
made efforts at searching for a solution, someone will be more than  
happy to help. Being lazy and posting a list of 50-100 rewrites, most of  
which are straightforward, is likely to be ignored.

> > Why?  
> > Because it breaks the logical flow of conversation, plus makes  
> > messages unreadable.
> > 
> > > Top-Posting is evil.

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

–  
Jim O.

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 2, 2010, 11:22am UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/11 "2010-11-02T11:22:33Z")

</div>

> > > Having a tool to capture 80% of the easy Apache configs might be  
> > > really helpful for folks.  
> > > [http://www.anilcetin.com/convert-apache-htaccess-to-nginx/](http://www.anilcetin.com/convert-apache-htaccess-to-nginx/)

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 2, 2010, 11:16am UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/12 "2010-11-02T11:16:14Z")

</div>

Agree,

laziness, we are lazy, most of computer users/programmers lazy… 🙂  
lazy, stupid, asshole, whatever you call it, thats it…  
what they say: “KISS, keep it simple stupid”, but I say also “KISC:  
keep it simple clever.”

anyway,  
an “automatic translater, as a program, or web service, or optionally,  
same rewrite works on nginx” is mostly preferable…

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 2, 2010, 12:08pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/13 "2010-11-02T12:08:27Z")

</div>

wauww… thanks.  
teşekkürler dostum…

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 2, 2010, 5:27pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/14 "2010-11-02T17:27:57Z")

</div>

You heavily need to re-arrange rewrites.

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 2, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/15 "2010-11-02T16:14:25Z")

</div>

mow its not working on my rules. this script only change RewriteRule to  
rewrite. nothing else.

Posted at Nginx Forum:

> **[Re: How to convert apache to nginx rewrite?](https://forum.nginx.org/read.php?2,146186,146932#msg-146932)**
>
> Its rewrite for phpBB mod - przemo.org. \[code\]RewriteEngine on #RewriteBase /forum RewriteRule ^cat(\[0-9\]\*)\\.htm$ ./index.php?c=$1 \[L,QSA\] # RewriteRule ^(forum|.\*-vf)(\[0-9\]+)-(\[0-9\]+),(\[0-9\]+)\\.htm$ ./viewforum.php?f=$2&topicdays=$3&am

---

<div class="post-metadata">

**Author:** ![dong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@dong](https://www.ruby-forum.com/u/dong)\
**Post date:** [November 3, 2010, 12:52pm UTC](https://www.ruby-forum.com/t/how-to-convert-apache-to-nginx-rewrite/198393/16 "2010-11-03T12:52:45Z")

</div>

But I dont know how…

Posted at Nginx Forum:

> **[Re: How to convert apache to nginx rewrite?](https://forum.nginx.org/read.php?2,146186,147184#msg-147184)**
>
> Its rewrite for phpBB mod - przemo.org. \[code\]RewriteEngine on #RewriteBase /forum RewriteRule ^cat(\[0-9\]\*)\\.htm$ ./index.php?c=$1 \[L,QSA\] # RewriteRule ^(forum|.\*-vf)(\[0-9\]+)-(\[0-9\]+),(\[0-9\]+)\\.htm$ ./viewforum.php?f=$2&topicdays=$3&am
