Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's $0 in nginx? (mod_rewrite)

I'm trying convert my Apache rewrite rules for my new nginx webserver, but I'm having problems translating this particular line:

RewriteRule ^(arin|barry|john|ross|danny).*$ /share/$0 [NC]

As for my old Apache server, this rule caused

http://example.com/danny/awesomeVideo.avi to view http://example.com/share/danny/awesomeVideo.avi instead, without the link changing.

To be honest, as my Apache setup was a long time ago, I'm not even sure whether or not the link not changing in the address bar for someone who views the file was due to this rule or not.

Most online converters will propose this rule for nginx:

rewrite ^/(arin|barry|john|ross|danny).*$ /share/$0 last;

Unfortunately, $0 seems to be faulty, as this is what I get when restarting nginx:

Restarting nginx: nginx: [emerg] unknown "0" variable

nginx: configuration file /etc/nginx/nginx.conf test failed`

Does anyone know how to express Apache's $0 in nginx?

like image 295
Chiru Avatar asked Jan 01 '14 15:01

Chiru


People also ask

What is $1 in nginx?

*$ $1/linux/$2.html break; redirect: This flag will do a temporary redirection using 302 HTTP code. This is mainly used when the replacement string is not http, or https, or $scheme.

What is $1 in Apache RewriteRule?

$1 represents the match from the first set of parentheses in the RewriteRule regex, not in the RewriteCond regex.

What is mod_rewrite used for?

mod_rewrite provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. Each rule can have an unlimited number of attached rule conditions, to allow you to rewrite URL based on server variables, environment variables, HTTP headers, or time stamps.

What is mod_rewrite module?

The mod_rewrite module is a rule-based Apache engine for rewriting URLs. The rules allow writing various queries to change URLs into the desired format. Some applications include page redirecting or proxy fetching. This article shows how to set up, configure, and rewrite URLs using mod_rewrite.


1 Answers

Try use $uri or $request_uri instead $0

like image 64
newman Avatar answered Oct 13 '22 00:10

newman