# Convert .htaccess for nginx

**URL:** <https://www.ruby-forum.com/t/convert-htaccess-for-nginx/202812>\
**Category:** NGINX\
**Created:** [February 6, 2011, 8:12pm UTC](https://www.ruby-forum.com/t/convert-htaccess-for-nginx/202812 "2011-02-06T20:12:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 6, 2011, 8:12pm UTC](https://www.ruby-forum.com/t/convert-htaccess-for-nginx/202812/1 "2011-02-06T20:12:11Z")

</div>

Hello,  
I have tryed to read about rewrite rules but I’m not able to handle  
this, Have already tryed online convert for .htaccess to nginx but when  
I restart my ngnix server I get error message

```auto
[emerg]: invalid parameter "/[L]" in /usr/local/nginx/conf/rrulesvco:24
configuration file /usr/local/nginx/conf/nginx.conf test failed
```

/usr/local/nginx/conf/rrulesvco is include in my nginx.conf file under  
my "location ~ .php$ { "

My old .htaccess looks like so:

```auto
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^([^.]*)/?$ index.php [L]
RewriteRule ^videos/(.*)/(.*)/(.*)/(.*)/(.*)
videos.php?cat=$1&sort=$3&time=$4&page=$5&seo_cat_name=$2 [L]
RewriteRule ^videos videos.php?%{QUERY_STRING} [L]
RewriteRule ^video/(.*)/(.*) watch_video.php?v=$1&%{QUERY_STRING} [L]
RewriteRule ^channels/(.*)/(.*)/(.*)/(.*)/(.*)
channels.php?cat=$1&sort=$3&time=$4&page=$5&seo_cat_name=$2 [L]
RewriteRule ^channels channels.php [L]
RewriteRule
^group/([a-zA-Z0-9].+) view_group.php?url=$1&%{QUERY_STRING} 
[L]
RewriteRule
^view_topic/([a-zA-Z0-9].+)_tid_([0-9]+) 
view_topic.php?tid=$2&%{QUERY_STRING}
[L]
RewriteRule ^groups/(.*)/(.*)/(.*)/(.*)/(.*)
groups.php?cat=$1&sort=$3&time=$4&page=$5&seo_cat_name=$2 [L]
RewriteRule ^groups groups.php [L]
RewriteRule ^create_group create_group.php [L]
RewriteRule ^sitemap.xml$ sitemap.php
RewriteRule ^signup signup.php
RewriteRule ^rss$ rss.php [nc]
RewriteRule ^rss/([a-zA-Z0-9].+)$
rss.php?mode=$1&%{QUERY_STRING} [nc]
RewriteRule ^desktop desktop.php [L]

```

Thanks

Posted at Nginx Forum:

> **[convert .htaccess for nginx](https://forum.nginx.org/read.php?2,172639,172639#msg-172639)**
>
> Hello, I have tryed to read about rewrite rules but I'm not able to handle this, Have already tryed online convert for .htaccess to nginx but when I restart my ngnix server I get error message \[code\] \[emerg\]: invalid parameter "/\[L\]" in...

---

<div class="post-metadata">

**Author:** ![tophi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9bcb4/32.png) [@tophi](https://www.ruby-forum.com/u/tophi)\
**Post date:** [February 8, 2011, 5:18pm UTC](https://www.ruby-forum.com/t/convert-htaccess-for-nginx/202812/2 "2011-02-08T17:18:59Z")

</div>

Thanks! It works on 100% now !

Posted at Nginx Forum:

> **[Re: convert .htaccess for nginx](https://forum.nginx.org/read.php?2,172639,173243#msg-173243)**
>
> Hello, I have tryed to read about rewrite rules but I'm not able to handle this, Have already tryed online convert for .htaccess to nginx but when I restart my ngnix server I get error message \[code\] \[emerg\]: invalid parameter "/\[L\]" in...

---

<div class="post-metadata">

**Author:** ![tophi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9bcb4/32.png) [@tophi](https://www.ruby-forum.com/u/tophi)\
**Post date:** [October 12, 2011, 11:52am UTC](https://www.ruby-forum.com/t/convert-htaccess-for-nginx/202812/3 "2011-10-12T11:52:34Z")

</div>

i search on google and found this thread… if still consufed i found 1  
link usefull to convert htaccess to nginx  
cekidot bekicot  
[http://www.anilcetin.com/convert-apache-htaccess-to-nginx/](http://www.anilcetin.com/convert-apache-htaccess-to-nginx/)

Posted at Nginx Forum:

> **[Re: convert .htaccess for nginx](https://forum.nginx.org/read.php?2,172639,216572#msg-216572)**
>
> Hello, I have tryed to read about rewrite rules but I'm not able to handle this, Have already tryed online convert for .htaccess to nginx but when I restart my ngnix server I get error message \[code\] \[emerg\]: invalid parameter "/\[L\]" in...

---

<div class="post-metadata">

**Author:** ![tophi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9bcb4/32.png) [@tophi](https://www.ruby-forum.com/u/tophi)\
**Post date:** [February 6, 2011, 8:37pm UTC](https://www.ruby-forum.com/t/convert-htaccess-for-nginx/202812/4 "2011-02-06T20:37:32Z")

</div>

On 6 Fev 2011 19h10 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> RewriteRule ^videos videos.php?%{QUERY\_STRING} [L] RewriteRule  
> create\_group.php [L] RewriteRule ^sitemap.xml$ sitemap.php  
> RewriteRule ^signup signup.php RewriteRule ^rss$ rss.php [nc]  
> RewriteRule ^rss/([a-zA-Z0-9].+)$ rss.php?mode=$1&%{QUERY\_STRING}  
> [nc] RewriteRule ^desktop desktop.php [L]

Have read the documentation at the wiki?

> **[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

Is shock full of examples.

Bear in mind that:

1. There’s no RewriteCond equivalent in Nginx. Instead you match a  
given location and the rewrite happens there.

2. Apart from the fact that Apache uses a more verbose syntax the  
Rewrite rule can be sort of copied from Apache to Nginx.

3. Flags, Apache - Nginx equivalence:

Here’s an example from your Apache rewrites:

1. Without condition:

RewriteRule ^channels/(._)/(._)/(._)/(._)/(.\*)  
channels.php?cat=$1&sort=$3&time=$4&page=$5&seo\_cat\_name=$2 [L]

rewrite ^channels/(._)/(._)/(._)/(._)/(.\*)  
channels.php?cat=$1&sort=$3&time=$4&page=$5&seo\_cat\_name=$2 last;

1. With a condition:

if ($query\_string ~ “base64\_encode._(._)”) {  
rewrite ^(?:[^.]\*)/?$ index.php last;  
}

Now you just have to do it for every other condition and rule in your  
Apache config.

— appa
