Simple path rewrite in Nginx, I can't get it to work.
from this:
/assets/sites/fpi/css/reset.css
to this:
/assets/sites/default/css/reset.css
my rule looks like this:
rewrite ^/assets/sites(.+)$ /assets/sites/default/$1 last;
/** UPDATE **/
Thanks for the helpful answers so far. I would like a more generic way to target the "fpi" section of the URL path.
Something like:
<pre>
rewrite ^(/assets/sites)/\w*/(.*)$ $1/default/$2 last;
</pre>
Which would match any part of that section so all urls matching this pattern:
<pre>
/assets/sites/fpi/css/reset.css
/assets/sites/gbc/css/reset.css
/assets/sites/ekg/css/reset.css
</pre>
would shift to:
<pre>
/assets/sites/default/css/reset.css
/assets/sites/default/css/reset.css
/assets/sites/default/css/reset.css
</pre>
Thanks
Instead of last
, use break
, redirect
or permanent
. The differences are subtle:
break
-containing rule was triggered. Unlike last
, no other rewrite rules will be processed from there on and the rule cannot be re-evaluated by itself . I'd advocate permanent
, personally. Give your visitors a chance to cache the CSS stylesheet.
Your regex does not match your specification. Use this:
rewrite ^(/assets/sites)/fpi/(.*)$ $1/default/$2 last;
Your regex in the example takes the fpi with it.
From the documentation:
rewrite last - completes processing of current rewrite directives and restarts the process (including rewriting) with a search for a match on the URI from all available locations.
Your rewritten URL will match the pattern that is being matched so it will continually rewrite it.
You should change the matcher (or the rewritten path) to not match it again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.