# Rewrite Rule convert

**URL:** <https://www.ruby-forum.com/t/rewrite-rule-convert/200031>\
**Category:** NGINX\
**Created:** [December 3, 2010, 7:55am UTC](https://www.ruby-forum.com/t/rewrite-rule-convert/200031 "2010-12-03T07:55:48Z")\
**Posts on this page:** 2\
**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:** [December 3, 2010, 7:55am UTC](https://www.ruby-forum.com/t/rewrite-rule-convert/200031/1 "2010-12-03T07:55:48Z")

</div>

I am a newer for the nginx  
I am tired to convert the rule form apache to nginx but it doesn’t  
work.  
Anyone can help and point out my error?  
Thanks

The Source Apache Rule:  
RewriteRule ^/?index.html$ /html/index.html [L]  
RewriteRule  
^((ajax/|accounts/|software/download|shortcut|flashcookie)/?._)$  
/index.php/$1 [L]  
RewriteRule ^/?((cn|en|tw)?/?([a-zA-Z][a-zA-Z0-9\_-]+)_.html)$  
/html/$1 [L]  
RewriteRule ^/?((cn|en|tw)?/?news/\d+).html$ /html/$1.html [L]

My Convert Rules for Nginx:  
rewrite ^/?index.html$ /html/index.html last;  
rewrite ^((ajax/|accounts/|software/download|shortcut|flashcookie)/?._)$  
/index.php/$1 last;  
rewrite ^//?((cn|en|tw)?/?([a-zA-Z][a-zA-Z0-9\_-]+)_.html)$ /html/$1  
last;  
rewrite ^/?((cn|en|tw)?/?news/\d+).html$ /html/$1.html last;

Now I link to my ajax/|accounts/|software/download|shortcut|flashcookie  
page, it show error 404

Posted at Nginx Forum:

> **[Rewrite Rule convert](https://forum.nginx.org/read.php?2,155200,155200#msg-155200)**
>
> I am a newer for the nginx I am tired to convert the rule form apache to nginx but it doesn't work. Anyone can help and point out my error? Thanks The Source Apache Rule: RewriteRule ^\\/?index\\.html$ /html/index.html \[L\] RewriteRule ^((ajax/|accounts

---

<div class="post-metadata">

**Author:** ![u-name](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ad7895/32.png) [@u-name](https://www.ruby-forum.com/u/u-name)\
**Post date:** [December 3, 2010, 8:25am UTC](https://www.ruby-forum.com/t/rewrite-rule-convert/200031/2 "2010-12-03T08:25:12Z")

</div>

On Fri, Dec 03, 2010 at 01:54:18AM -0500, u-name wrote:

> /index.php/$1 [L]  
> rewrite ^/?((cn|en|tw)?/?news/\d+).html$ /html/$1.html last;
> 
> Now I link to my ajax/|accounts/|software/download|shortcut|flashcookie  
> page, it show error 404

Sorry, it’s not easy to understand these regexs.  
What does “^/?((cn|en|tw)?/?news/\d+).html$” mean ?  
Should it match “/ennews/5.html”, for example ?

You should location instead rewrites, for example:

locaiton = /index.html {  
root /path/to/html;  
}

–  
Igor S.

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