# Nginx Rewrite Apache?

**URL:** <https://www.ruby-forum.com/t/nginx-rewrite-apache/205635>\
**Category:** NGINX\
**Created:** [April 11, 2011, 11:19pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635 "2011-04-11T23:19:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 11, 2011, 11:19pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/1 "2011-04-11T23:19:49Z")

</div>

Hi  
I have problem with rewrite from apache  
RewriteEngine On

RewriteRule  
^[A-Z]{3}[a-z]{2}[0-9]{4}[a-z]{3}[0-9]{4}[A-Z]{2}[a-z]{1}[0-9]{1}/(.+)$  
files/$1

rewrite  
^[A-Z]{3}[a-z]{2}[0-9]{4}[a-z]{3}[0-9]{4}[A-Z]{2}[a-z]{1}[0-9]{1}/(.+)$  
/files/$1 last;  
This rule dosent work…  
Problem is { }  
On apache this work  
[http://xx.xx.xx/QJNqq0821sxz7200DAp0/Si.s\_sred.iowi.cze.part5.rar](http://xx.xx.xx/QJNqq0821sxz7200DAp0/Si.s_sred.iowi.cze.part5.rar)  
rewriting to  
to [http://xx.xx.xx/files/Si.s\_sred.iowi.cze.part5.rar](http://xx.xx.xx/files/Si.s_sred.iowi.cze.part5.rar) but  
[http://xx.xx.xx/dsadasdaddsads/Si.s\_sred.iowi.cze.part5.rar](http://xx.xx.xx/dsadasdaddsads/Si.s_sred.iowi.cze.part5.rar) musnt not  
work

Posted at Nginx Forum:

> **[Nginx Rewrite Apache?](https://forum.nginx.org/read.php?2,190307,190307#msg-190307)**
>
> Hi I have problem with rewrite from apache RewriteEngine On RewriteRule ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ files/$1 rewrite ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ /files/$1 last;

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 11, 2011, 11:32pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/2 "2011-04-11T23:32:47Z")

</div>

On 11 Abr 2011 22h19 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> /files/$1 last; This rule dosent work… Problem is { } On apache  
> this work  
> [http://xx.xx.xx/QJNqq0821sxz7200DAp0/Si.s\_sred.iowi.cze.part5.rar](http://xx.xx.xx/QJNqq0821sxz7200DAp0/Si.s_sred.iowi.cze.part5.rar)  
> rewriting to to [http://xx.xx.xx/files/Si.s\_sred.iowi.cze.part5.rar](http://xx.xx.xx/files/Si.s_sred.iowi.cze.part5.rar)  
> but [http://xx.xx.xx/dsadasdaddsads/Si.s\_sred.iowi.cze.part5.rar](http://xx.xx.xx/dsadasdaddsads/Si.s_sred.iowi.cze.part5.rar)  
> musnt not work

From: [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpRewriteModule#rewrite)

```
  Note: for curly braces( { and } ), as they are used both in
  regexes and for block control, to avoid conflicts, regexes with
  curly braces are to be enclosed with double quotes (or single
  quotes). For example, to rewrite URLs like:

  /photos/123456
  to:

  /path/to/photos/12/1234/123456.png
  use the following (note the quotes enclosing the regex):

  rewrite "/photos/([0-9] {2})([0-9] {2})([0-9] {2})" 

```

/path/to/photos/$1/$1$2/$1$2$3.png;

— appa

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 11, 2011, 11:37pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/3 "2011-04-11T23:37:43Z")

</div>

-------- Original-Nachricht --------

> Datum: Mon, 11 Apr 2011 17:19:23 -0400  
> Von: “Adrian Janeczek” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Betreff: Nginx Rewrite Apache?

> /files/$1 last;  
> This rule dosent work…  
> Problem is { }

So why don’t you rewrite that regexp to not use {}?  
rewrite  
“^/[A-Z][A-Z][A-Z][a-z][a-z][0-9][0-9][0-9][0-9][a-z][a-z][a-z][0-9][0-9][0-9][0-9][A-Z][A-Z][a-z][0-9]/(.+)$”  
/files/$1 last;

If you ask me, your original regexp should be enclosed in quotes:  
rewrite  
"^/[A-Z]{3}[a-z]{2}[0-9]{4}[a-z]{3}[0-9]{4}[A-Z]{2}[a-z][0-9]/(.+)$  
/files/$1 last;

Btw: using “[0-9]{1}” is equal to “[0-9]”

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

–  
NEU: FreePhone - kostenlos mobil telefonieren und surfen!  
Jetzt informieren: [http://www.gmx.net/de/go/freephone](http://www.gmx.net/de/go/freephone)

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 11, 2011, 11:49pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/4 "2011-04-11T23:49:25Z")

</div>

Look this is example rewrite apache

RewriteRule  
^[A-Z]{3}[a-z]{2}[0-9]{4}[a-z]{3}[0-9]{4}[A-Z]{2}[a-z]{1}[0-9]{1}/(.+)$  
files/$1  
3 characters A-Z  
2 characters a-z  
4characters 0-9  
u know?  
and last code is  
ADDad0000asa0000AAp0  
QJNqq0821sxz4230QAp0

Posted at Nginx Forum:

> **[Re: Nginx Rewrite Apache?](https://forum.nginx.org/read.php?2,190307,190319#msg-190319)**
>
> Hi I have problem with rewrite from apache RewriteEngine On RewriteRule ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ files/$1 rewrite ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ /files/$1 last;

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 11, 2011, 11:50pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/5 "2011-04-11T23:50:40Z")

</div>

i try use “” but now work rewrite

Posted at Nginx Forum:

> **[Re: Nginx Rewrite Apache?](https://forum.nginx.org/read.php?2,190307,190321#msg-190321)**
>
> Hi I have problem with rewrite from apache RewriteEngine On RewriteRule ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ files/$1 rewrite ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ /files/$1 last;

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 11, 2011, 11:51pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/6 "2011-04-11T23:51:17Z")

</div>

On 11 Abr 2011 22h19 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi  
> I have problem with rewrite from apache  
> RewriteEngine On
> 
> RewriteRule  
> \[1\]{3}[a-z]{2}[0-9]{4}[a-z]{3}[0-9]{4}[A-Z]{2}[a-z]{1}[0-9]{1}/(.+)$  
> files/$1

Here’s how to shorten your regex:

rewrite “\[2\]{3}[a-z]{2}\d{4}[a-z]{3}\d{4}[A-Z]{2}[a-z]\d/(.+)$”  
files/$1;

— appa

* * *

1. A-Z 

2. A-Z

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 11, 2011, 11:59pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/7 "2011-04-11T23:59:18Z")

</div>

dosen’t work  
[http://s1.rapidox.pl/QJNqq0821sxz7200DAp0/Si.s\_sred.iowi.cze.part5.rar](http://s1.rapidox.pl/QJNqq0821sxz7200DAp0/Si.s_sred.iowi.cze.part5.rar)

[http://s1.rapidox.pl/files/Si.s\_sred.iowi.cze.part5.rar](http://s1.rapidox.pl/files/Si.s_sred.iowi.cze.part5.rar)

rewrite \>  
rewrite “^[A-Z]{3}[a-z]{2}\d{4}[a-z]{3}\d{4}[A-Z]{2}[a-z]\d/(.+)$”  
files/$1;

i trying this but not work…  
rewrite “([A-Z] {3})([a-z] {2})([0-9] {4})([a-z] {3})([0-9] {4})([A-Z]  
{2})([a-z] {1})([0-9] {1})/(.+)$” /files/$1 last;

[http://pastebin.com/raw.php?i=HZZBStcd](http://pastebin.com/raw.php?i=HZZBStcd)

Posted at Nginx Forum:

> **[Re: Nginx Rewrite Apache?](https://forum.nginx.org/read.php?2,190307,190326#msg-190326)**
>
> Hi I have problem with rewrite from apache RewriteEngine On RewriteRule ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ files/$1 rewrite ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ /files/$1 last;

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 12, 2011, 12:14am UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/8 "2011-04-12T00:14:07Z")

</div>

On 11 Abr 2011 22h59 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> {4})([a-z] {3})([0-9] {4})([A-Z] {2})([a-z] {1})([0-9] {1})/(.+)$"  
> /files/$1 last;

This is not the same thing. You’re capturing a lot of stuff. In the  
original expression you sent only the last pattern was a capture  
group. And from the above example it seems that only the _last_  
pattern is in a capture group. I’m assuming that:

[http://s1.rapidox.pl/files/Si.s\_sred.iowi.cze.part5.rar](http://s1.rapidox.pl/files/Si.s_sred.iowi.cze.part5.rar) is your  
desired result from the rewrite.

If so remove all () except the last one. Just copy the expression I’ve  
sent in a previous message. It should do the trick.

— appa

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 12, 2011, 12:15am UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/9 "2011-04-12T00:15:21Z")

</div>

yep but this work

u know what i want  
AAAaa0000aaa0000AAa0  
this is example rewrite  
rewrite “/([A-Z] {3})([a-z] {2})([0-9] {4})([a-z] {3})([0-9] {4})([A-Z]  
{2})([a-z] {1})([0-9] {1})” /files/$1;  
but dont work

Posted at Nginx Forum:

> **[Re: Nginx Rewrite Apache?](https://forum.nginx.org/read.php?2,190307,190337#msg-190337)**
>
> Hi I have problem with rewrite from apache RewriteEngine On RewriteRule ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ files/$1 rewrite ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ /files/$1 last;

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 12, 2011, 12:09am UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/10 "2011-04-12T00:09:46Z")

</div>

-------- Original-Nachricht --------

> Datum: Mon, 11 Apr 2011 17:59:01 -0400  
> Von: “Adrian Janeczek” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Betreff: Re: Nginx Rewrite Apache?

> rewrite “([A-Z] {3})([a-z] {2})([0-9] {4})([a-z] {3})([0-9] {4})([A-Z]  
> {2})([a-z] {1})([0-9] {1})/(.+)$” /files/$1 last;

What is that space before the curly brackets? Remove them!  
rewrite  
“^/(?:[A-Z]{3})(?:[a-z]{2})(?:[0-9]{4})(?:[a-z]{3})(?:[0-9]{4})(?:[A-Z]{2})(?:[a-z]{1})(?:[0-9]{1})/(.+)$”  
/files/$9 last;

> [http://pastebin.com/raw.php?i=HZZBStcd](http://pastebin.com/raw.php?i=HZZBStcd)

Ohhh boy. Location block inside another location block?

> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,190307,190326#msg-190326](http://forum.nginx.org/read.php?2,190307,190326#msg-190326)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit  
gratis Handy-Flat! [http://portal.gmx.net/de/go/dsl](http://portal.gmx.net/de/go/dsl)

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 12, 2011, 12:22am UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/11 "2011-04-12T00:22:44Z")

</div>

On 11 Abr 2011 22h59 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> {4})([a-z] {3})([0-9] {4})([A-Z] {2})([a-z] {1})([0-9] {1})/(.+)$"  
> /files/$1 last;
> 
> [http://pastebin.com/raw.php?i=HZZBStcd](http://pastebin.com/raw.php?i=HZZBStcd)

You should use try\_files instead of mimicking the dyslexic mod\_rewrite  
way of doing things with .htaccess.

location ~\*  
^.+.(?:jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov|ico){  
access\_log off;  
expires 30d;  
}

try\_files $uri $uri/ =404;

Something of that kind.

— appa

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 12, 2011, 12:15am UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/12 "2011-04-12T00:15:58Z")

</div>

On Mon, Apr 11, 2011 at 05:59:01PM -0400, Adrian Janeczek wrote:

Hi there,

> dosen’t work  
> [http://s1.rapidox.pl/QJNqq0821sxz7200DAp0/Si.s\_sred.iowi.cze.part5.rar](http://s1.rapidox.pl/QJNqq0821sxz7200DAp0/Si.s_sred.iowi.cze.part5.rar)
> 
> [http://s1.rapidox.pl/files/Si.s\_sred.iowi.cze.part5.rar](http://s1.rapidox.pl/files/Si.s_sred.iowi.cze.part5.rar)
> 
> rewrite \>  
> rewrite “\[1\]{3}[a-z]{2}\d{4}[a-z]{3}\d{4}[A-Z]{2}[a-z]\d/(.+)$”  
> files/$1;

The nginx debug log is usually good.

In this case, you would see something like

“\[2\]{3}[a-z]{2}\d{4}[a-z]{3}\d{4}[A-Z]{2}[a-z]\d/(.+)$” does not  
match “/QJNqq0821sxz7200DAp0/Si.s\_sred.iowi.cze.part5.rar”, client:  
127.0.0.1, server: , request: "GET  
/QJNqq0821sxz7200DAp0/Si.s\_sred.iowi.cze.part5.rar

In nginx, the request starts with “/”, so if you use “^”, the next  
character must match “/” or the regex won’t match.

> i trying this but not work…  
> rewrite “([A-Z] {3})([a-z] {2})([0-9] {4})([a-z] {3})([0-9] {4})([A-Z]  
> {2})([a-z] {1})([0-9] {1})/(.+)$” /files/$1 last;

This fails to match because the spaces should not be there. The example  
on  
the wiki should probably be fixed, if someone already has a login there?

If you erase the spaces, then the regex does match, but the replacement  
$1 is “QJN”, because of the parentheses.

Your original rewrite line wrapped in double quotes should work, with  
the initial “^” changed to “^/” (and the replacement “files” becoming  
“/files”.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

1. A-Z 

2. A-Z

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 15, 2011, 11:37pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/13 "2011-04-15T23:37:00Z")

</div>

I’ve next trouble

This for nginx  
RewriteEngine On  
RewriteBase /

RewriteCond %{HTTP\_HOST} ^www.zzz.pl$ [NC]  
RewriteRule ^(.\*)$ [http://zzz.pl/$1](http://zzz.pl/$1) [R=301,L]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} !-d

RewriteRule .\* index.php?$0 [PT,L]  
This is uri but i use this conf

and this not work

server {  
listen 80;  
server\_name zzz.lifeisbrutal.pl;

# access\_log /var/log/nginx/zzz.log;

# error\_log /var/log/nginx/zzz.log;

```
root /home/zzz/public_html;
index index.php index.html index.htm;

location / {
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?$1 last;
    }
}

location ~ .php($|/) {

    set $script $uri;
    set $path_info "";

    if ($uri ~ "^(.+.php)(/.+)") {
        set $script $1;
        set $path_info $2;
    }

    fastcgi_pass 127.0.0.1:9002;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$script;
    fastcgi_param SCRIPT_NAME $script;
    fastcgi_param PATH_INFO $path_info;

    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;

    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT $document_root;
    fastcgi_param SERVER_PROTOCOL $server_protocol;

    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx;

    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param REDIRECT_STATUS 200;

}

```

}

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

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 12, 2011, 12:47am UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/14 "2011-04-12T00:47:22Z")

</div>

Thanks this is work  
rewrite  
“^/(?:[A-Z]{3})(?:[a-z]{2})(?:[0-9]{4})(?:[a-z]{3})(?:[0-9]{4})(?:[A-Z]{2})(?:[a-z]{1})(?:[0-9]{1})/(.+)$”  
/files/$1 last;

Posted at Nginx Forum:

> **[Re: Nginx Rewrite Apache?](https://forum.nginx.org/read.php?2,190307,190345#msg-190345)**
>
> Hi I have problem with rewrite from apache RewriteEngine On RewriteRule ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ files/$1 rewrite ^\[A-Z\]{3}\[a-z\]{2}\[0-9\]{4}\[a-z\]{3}\[0-9\]{4}\[A-Z\]{2}\[a-z\]{1}\[0-9\]{1}/(.+)$ /files/$1 last;

---

<div class="post-metadata">

**Author:** ![Adrian\_Janeczek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@Adrian\_Janeczek](https://www.ruby-forum.com/u/Adrian_Janeczek)\
**Post date:** [April 18, 2011, 1:58pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-apache/205635/15 "2011-04-18T13:58:20Z")

</div>

On Fri, Apr 15, 2011 at 05:36:09PM -0400, Adrian Janeczek wrote:

Hi there,

> This is uri but i use this conf

> and this not work

What do you expect to see it do; and what do you see it do instead?

As before, the debug log ([A debugging log](http://nginx.org/en/docs/debugging_log.html))  
is frequently helpful in finding the problem cause.

> ```
> location / {
> if (!-e $request_filename) {
> rewrite ^/(.*)$ /index.php?$1 last;
> }
> }
> 
> ```

That may be better with try\_files  
([GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpCoreModule#try_files)), but probably  
isn’t the main problem you’re seeing.

> ```
> location ~ .php($|/) {
> 
> set $script $uri;
> set $path_info "";
> 
> if ($uri ~ "^(.+.php)(/.+)") {
> set $script $1;
> set $path_info $2;
> }
> 
> ```

Using “if” inside “location” for anything other than “return” or  
“rewrite…last” is usually unwise. See [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/IfIsEvil)  
for details.

In this case, I would suggest using fastcgi\_split\_path\_info, since  
that’s  
what you’re trying to do.

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

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
