# Rewrite rule for nginx from Apache

**URL:** <https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154>\
**Category:** NGINX\
**Created:** [November 18, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154 "2009-11-18T16:17:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [November 18, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/1 "2009-11-18T16:17:23Z")

</div>

Can anyone tell me how to rewrite this rules from apache:

RewriteEngine On  
RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 [L]  
RewriteRule ^([0-9a-zA-Z]{1,6})$ redirect.php?url=$1 [L]

to nginx?

Thanks!

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [November 18, 2009, 4:38pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/2 "2009-11-18T16:38:52Z")

</div>

Hello Robert,

Wednesday, November 18, 2009, 9:17:23 PM, you wrote:

> Can anyone tell me how to rewrite this rules from apache:

> RewriteEngine On  
> RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 [L]  
> RewriteRule ^([0-9a-zA-Z]{1,6})$ redirect.php?url=$1 [L]

> to nginx?

> Thanks!

location ~ ^/shorten/(?.\*)$ {  
root …;  
fastcgi\_pass …;  
fastcgi\_param SCRIPT\_NAME /shorten.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root/shorten.php;  
fastcgi\_param QUERY\_STRING longurl=$longurl;  
}

location ~ “^/(?[0-9a-zA-Z]{1,6})$” {  
root …;  
fastcgi\_pass …;  
fastcgi\_param SCRIPT\_NAME /redirect.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root/redirect.php;  
fastcgi\_param QUERY\_STRING url=$url;  
}

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [November 19, 2009, 11:28am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/3 "2009-11-19T11:28:17Z")

</div>

Thx, can u also help me with this:

RewriteCond %{REQUEST\_URI} /([0-9a-z]{6})$ [NC]  
RewriteRule ^(.\*) [http://www.example.com/forward.php?%1](http://www.example.com/forward.php?%251) [L]

Thanks again!

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [November 19, 2009, 12:07pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/4 "2009-11-19T12:07:44Z")

</div>

Hello Robert,

Thursday, November 19, 2009, 4:28:17 PM, you wrote:

> Thx, can u also help me with this:

> RewriteCond %{REQUEST\_URI} /([0-9a-z]{6})$ [NC]  
> RewriteRule ^(.\*) [http://www.example.com/forward.php?%1](http://www.example.com/forward.php?%251) [L]

> Thanks again!

location ~ “/(?[0-9a-z]{6})$” {  
rewrite ^ [http://www.example.com/forward.php?$fwd](http://www.example.com/forward.php?$fwd) last;  
}

or

location ~ “^/(?[0-9a-z]{6})$” {  
rewrite ^ [http://www.example.com/forward.php?$fwd](http://www.example.com/forward.php?$fwd) last;  
}

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [November 19, 2009, 8:17pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/5 "2009-11-19T20:17:23Z")

</div>

Hey, thanks for the help, but Im not getting how do you actually do it.

For example I got a new rewrite rule from Apache

RewriteOptions MaxRedirects=1  
RewriteBase /  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteCond %{REQUEST\_FILENAME} !-l  
RewriteRule ^([a-zA-Z0-9\_-]+)$ redirect.php?alias=$1 [L]

and did this:

location ~ “^/(?([a-zA-Z0-9\_-]))$” {  
root $site\_root;  
fastcgi\_pass unix:/var/tmp/php-fastcgi.socket;  
fastcgi\_param SCRIPT\_NAME /redirect.php;  
fastcgi\_param SCRIPT\_FILENAME $site\_root/redirect.php;  
fastcgi\_param QUERY\_STRING alias=$alias;  
}

and it doesn’t work. Do you know why?

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 13, 2011, 1:59am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/6 "2011-05-13T01:59:29Z")

</div>

Please can you help me to convert this to nginx

RewriteEngine on
# If you are having problems or are using VirtualDocumentRoot, uncomment

this line and set it to your directory.

# RewriteBase /maindir/

RewriteOptions MaxRedirects=30  
RewriteCond %{ENV:REDIRECT\_STATUS} 200  
RewriteRule .\* - [L]

RewriteCond %{REQUEST\_FILENAME} -s [OR]  
RewriteCond %{REQUEST\_FILENAME} -l [OR]  
RewriteCond %{REQUEST\_FILENAME} -d

RewriteRule ^.\*$ - [NC,L]

RewriteRule ^index(._)$ index.php  
[QSA]  
RewriteRule ^chat/._ pages.php  
[QSA]  
RewriteRule ^Songs(._)$  
showcat.php?g=2 [QSA]  
RewriteRule ^Jokes(._)$  
showcat.php?g=3 [QSA]  
RewriteRule ^Ash3ar(._)$  
showcat.php?g=4 [QSA]  
RewriteRule ^iraq/._ showcat.php  
[QSA]  
RewriteRule ^Song/.\* sounds.php  
[QSA]  
RewriteRule ^Joke/.\* jokes.php  
[QSA]  
RewriteRule ^Poem/.\* poems.php  
[QSA]  
RewriteRule ^link/.\* advs.php  
[QSA]  
RewriteRule ^search/.\* search.php  
[QSA]  
RewriteRule ^adv-conditions(._)$  
ad.php?go=conditions [NC]  
RewriteRule ^adv-payments(._)$  
ad.php?go=payments [NC]

RewriteCond %{REQUEST\_FILENAME} -s [OR]  
RewriteCond %{REQUEST\_FILENAME} -l [OR]  
RewriteCond %{REQUEST\_FILENAME} -d

RewriteRule ^._$ - [NC,L]  
RewriteRule ^(?:(._?)(?:/|$))(.\*|$)$ $1.php?r=$2 [QSA]

 SecFilterEngine Off SecFilterScanPOST Off mod\_gzip\_on No

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,23868,197702#msg-197702](http://forum.nginx.org/read.php?2,23868,197702#msg-197702)

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 13, 2011, 2:19am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/7 "2011-05-13T02:19:53Z")

</div>

using [http://www.anilcetin.com/convert-apache-htaccess-to-nginx/](http://www.anilcetin.com/convert-apache-htaccess-to-nginx/) , I got  
this:

#ignored: condition 0  
#ignored: “-” thing used or unknown variable in regex/rew  
if (-e $request\_filename){  
set $rule\_1 1;  
}  
if ($request\_filename ~ “-l”){  
set $rule\_1 1;  
}  
if (-d $request\_filename){  
set $rule\_1 1;  
}  
if ($rule\_1 = “1”){  
#ignored: “-” thing used or unknown variable in regex/rew  
}  
rewrite ^/index(._)$ /;  
rewrite ^/chat/._ /;  
rewrite ^/Songs(._)$ /;  
rewrite ^/Jokes(._)$ /;  
rewrite ^/Ash3ar(._)$ /;  
rewrite ^/iraq/._ /;  
rewrite ^/Song/.\* /;  
rewrite ^/Joke/.\* /;  
rewrite ^/Poem/.\* /;  
rewrite ^/link/.\* /;  
rewrite ^/search/.\* /;  
rewrite ^/adv-conditions(._)$ /;  
rewrite ^/adv-payments(._)$ /;  
if (-e $request\_filename){  
set $rule\_15 1;  
}  
if ($request\_filename ~ “-l”){  
set $rule\_15 1;  
}  
if (-d $request\_filename){  
set $rule\_15 1;  
}  
if ($rule\_15 = “1”){  
#ignored: “-” thing used or unknown variable in regex/rew  
}  
rewrite ^/(?:(._?)(?:/|$))(._|$)$ /$1.php?r=$2;

–  
omega13a  
Owner and Founder of UFT  
[http://www.fedtrek.com](http://www.fedtrek.com)

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 14, 2011, 11:39pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/8 "2011-05-14T23:39:32Z")

</div>

;(

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,198081#msg-198081)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 13, 2011, 3:09am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/9 "2011-05-13T03:09:14Z")

</div>

well first of all thank you for you quick reply …  
but i’ve tried this tool and it’s not working…  
i there any way to know the basics of the ngnix???

other wise look at the rewrite model

rewrite ^/index(._)$ /;  
rewrite ^/chat/._ /;  
rewrite ^/Songs(._)$ /;  
rewrite ^/Jokes(._)$ /;  
rewrite ^/Ash3ar(._)$ /;  
rewrite ^/iraq/._ /;  
rewrite ^/Song/.\* /;  
rewrite ^/Joke/.\* /;  
rewrite ^/Poem/.\* /;  
rewrite ^/link/.\* /;  
rewrite ^/search/.\* /;  
rewrite ^/adv-conditions(._)$ /;  
rewrite ^/adv-payments(._)$ /;

it haven’t consider the file file names … so i’m little bit confused  
about that tool  
and so it didn’t work

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,197717#msg-197717)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 18, 2011, 12:52am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/10 "2011-05-18T00:52:05Z")

</div>

First of all thank you very much mr Igor This is a great help for me  
but as i’m new to nginx so i’m little bit careful  
but i have afew more things to ask about

do i have to make any defination to these params

SCRIPT\_FILENAME  
maindir

which is used as  
fastcgi\_param SCRIPT\_FILENAME /path/to/script/pages.php;  
AND  
location /maindir/chat/

Or they just have to be written as they are??

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,198889#msg-198889)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 15, 2011, 2:50pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/11 "2011-05-15T14:50:55Z")

</div>

On Sat, May 14, 2011 at 05:38:49PM -0400, the\_traveller wrote:

> ;(

Rewrite rules are not configuration means. They are primitive  
programming  
language that is too hard to understand. For example, these

RewriteRule ^chat/.\* pages.php [QSA]  
RewriteRule ^Songs(.\*)$ showcat.php?g=2 [QSA]

may be translated to

location /maindir/chat/ {  
fastcgi\_pass …  
fastcgi\_param SCRIPT\_FILENAME /path/to/script/pages.php;  
fastcgi\_param QUERY\_STRING $args;  
…  
}

location /maindir/Songs/ {  
fastcgi\_pass …  
fastcgi\_param SCRIPT\_FILENAME /path/to/script/showcat.php;  
fastcgi\_param QUERY\_STRING g=2$is\_args$args;  
…  
}

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 19, 2011, 4:52am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/12 "2011-05-19T04:52:50Z")

</div>

Hello i am new to nginx and i need some help to convert my .htaccess, i  
have tried some shit but that not work …

Options FollowSymLinks  
RewriteEngine On

RewriteRule ^(._).php/img/(._)$ img/$2 [C]  
RewriteRule ^/img/(.\*)$ img/$2 [QSA,L]

RewriteCond %{REQUEST\_FILENAME} !^scriptsFtp.\*$

RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ index.php [QSA,L]

Thanks

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,199175#msg-199175)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 18, 2011, 8:49am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/13 "2011-05-18T08:49:41Z")

</div>

On Tue, May 17, 2011 at 06:51:33PM -0400, the\_traveller wrote:

> First of all thank you very much mr Igor This is a great help for me  
> but as i’m new to nginx so i’m little bit careful  
> but i have afew more things to ask about
> 
> do i have to make any defination to these params
> 
> SCRIPT\_FILENAME  
> maindir

“/maindir/” is from  
RewriteBase /maindir/

By default it is “/”, for example,

location /chat/

SCRIPT\_FILENAME is FastCGI parameter which contains file system script  
name.

> which is used as  
> fastcgi\_param SCRIPT\_FILENAME /path/to/script/pages.php;  
> AND  
> location /maindir/chat/
> 
> Or they just have to be written as they are??

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 20, 2011, 10:02pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/14 "2011-05-20T22:02:33Z")

</div>

thx i gonna to try it tommorow 😉

the system is used for subdomain with a wildcard, example  
[toto.domain.com](http://toto.domain.com) show a mini website for toto and same things for 300  
other users, the website is the same but the content depend of the name  
of the subdomain, all is stored in mysql for images and such …

sorry for my english …

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,199607#msg-199607)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 23, 2011, 2:32am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/15 "2011-05-23T02:32:40Z")

</div>

Thanks that work really fine 😉

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,199984#msg-199984)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 20, 2011, 1:20pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/16 "2011-05-20T13:20:17Z")

</div>

On Wed, May 18, 2011 at 10:52:39PM -0400, ltss wrote:

> RewriteCond %{REQUEST\_FILENAME} !-d  
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteRule ^(.\*)$ index.php [QSA,L]

It’s not easy to understand what these .htaccess should do.  
Probably this:

root /path/to/files;

location / {  
try\_files $uri $uri/ /index.php?$args;  
}

location /scriptsFtp {  
…  
}

location ~ ^(._).php/img/(._)$ {  
alias /path/to/img/$2;  
}

location ~ .php$ {  
fastcgi\_pass …  
…  
}

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 25, 2011, 1:37pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/17 "2011-05-25T13:37:40Z")

</div>

On Mon, May 23, 2011 at 01:18:30PM -0400, the\_traveller wrote:

> }
> 
> and the Original Apache rule is  
> RewriteRule ^Joke/.\* jokes.php [QSA]
> 
> sposing that the script is in the public dir of the ftp  
> is my try right??

SCRIPT\_FILENAME should point to a file, for example,  
/usr/www/scripts/jokes.php.

> and also is the three dots in the second line  
> fastcgi\_pass …  
> and before the closing tag  
> …  
> }  
> is this is right or i have to remove them ??
> 
> thanks alot for ur help  
> and if i have removed them

dots means that you should add your specific paramters, that is,

```
 fastcgi_pass backend:9000;

```

etc.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 25, 2011, 8:30pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/18 "2011-05-25T20:30:51Z")

</div>

I know i’m alittle bit annoying

but can you show me how i must write the rule  
the path of the script jokes.php is in the public\_html dir  
and it should talks the args like that  
jokes.php?j=$1

so in Apache i used to make the rule like that  
RewriteRule ^Joke/.\* jokes.php [QSA]

but i alwayes have the sever error on all of my tries

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,200852#msg-200852)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 23, 2011, 7:18pm UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/19 "2011-05-23T19:18:54Z")

</div>

Hi mr Igor  
I’m sory coz i toke alittle bit too long

so if i have to make any ngnix rule i have to make it like that by ex:

location /Joke/ {  
fastcgi\_pass …  
fastcgi\_param SCRIPT\_FILENAME /jokes.php;  
fastcgi\_param QUERY\_STRING $args;  
…  
}

and the Original Apache rule is  
RewriteRule ^Joke/.\* jokes.php [QSA]

sposing that the script is in the public dir of the ftp  
is my try right??

and also is the three dots in the second line  
fastcgi\_pass …  
and before the closing tag  
…  
}  
is this is right or i have to remove them ??

thanks alot for ur help  
and if i have removed them

Posted at Nginx Forum:

> **[Re: Rewrite rule for nginx from Apache](https://forum.nginx.org/read.php?2,23868,200161#msg-200161)**
>
> Can anyone tell me how to rewrite this rules from apache: RewriteEngine On RewriteRule ^shorten/(.\*)$ shorten.php?longurl=$1 \[L\] RewriteRule ^(\[0-9a-zA-Z\]{1,6})$ redirect.php?url=$1 \[L\] to nginx? Thanks! -- Posted via http://www.ruby-fo

---

<div class="post-metadata">

**Author:** ![sovok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sovok](https://www.ruby-forum.com/u/sovok)\
**Post date:** [May 26, 2011, 9:05am UTC](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154/20 "2011-05-26T09:05:37Z")

</div>

On Wed, May 25, 2011 at 02:30:28PM -0400, the\_traveller wrote:

> I know i’m alittle bit annoying
> 
> but can you show me how i must write the rule  
> the path of the script jokes.php is in the public\_html dir  
> and it should talks the args like that  
> jokes.php?j=$1

Where does this public\_html directory reside ?  
/usr/local/www, /home/user/, or anything else ?

–  
Igor S.

[Next page](https://www.ruby-forum.com/t/rewrite-rule-for-nginx-from-apache/179154.md?page=2)
