Nginx Rewrite Apache?

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
rewriting to
to 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 musnt not
work

Posted at Nginx Forum:

On 11 Abr 2011 22h19 WEST, [email protected] 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
rewriting to to 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
musnt not work

From: Module ngx_http_rewrite_module

  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

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

Datum: Mon, 11 Apr 2011 17:19:23 -0400
Von: “Adrian Janeczek” [email protected]
An: [email protected]
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
[email protected]
nginx Info Page


NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: Handytarif Vergleich 2023 | alle Anbieter vergleichen | GMX

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:

i try use “” but now work rewrite

Posted at Nginx Forum:

On 11 Abr 2011 22h19 WEST, [email protected] wrote:

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

Here’s how to shorten your regex:

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

— appa

dosen’t work
http://s1.rapidox.pl/QJNqq0821sxz7200DAp0/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

Posted at Nginx Forum:

On 11 Abr 2011 22h59 WEST, [email protected] 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 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

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:

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

Datum: Mon, 11 Apr 2011 17:59:01 -0400
Von: “Adrian Janeczek” [email protected]
An: [email protected]
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

Ohhh boy. Location block inside another location block?

Posted at Nginx Forum:
Re: Nginx Rewrite Apache?


nginx mailing list
[email protected]
nginx Info Page


GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
gratis Handy-Flat! Aktuelle Nachrichten aus Politik, Wirtschaft & Panorama | GMX

On 11 Abr 2011 22h59 WEST, [email protected] 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

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

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/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;

The nginx debug log is usually good.

In this case, you would see something like

“^[A-Z]{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. [email protected]

I’ve next trouble

This for nginx
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.zzz.pl$ [NC]
RewriteRule ^(.*)$ 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:

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:

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)
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
(Module ngx_http_core_module), 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 If is Evil… when used in location context | NGINX
for details.

In this case, I would suggest using fastcgi_split_path_info, since
that’s
what you’re trying to do.

http://wiki.nginx.org/HttpFcgiModule#fastcgi_split_path_info

Good luck with it,

f

Francis D. [email protected]