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?
*$ $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.
$1 represents the match from the first set of parentheses in the RewriteRule regex, not in the RewriteCond regex.
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.
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.
Try use $uri
or $request_uri
instead $0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With