简体   繁体   中英

Apply rewrite rule to nginx vhost from apache vhost

I'm making some tests with nginx.

He works fine, but i'm unable to apply some rewrite rules from apache and nginx doc is not really easy.

Goal : everything has to be rewrited on the /index.php file instead of extra and adminer.

If i browse to http://server/extra/someThing , it's OK, the controller.php file is called.

But for /adminer, i just want to prevent /adminer to be rewrited by the last rule.

location / {
    rewrite ^/extra /extra/controller.php break;
    #rewrite ^/adminer - break;
    rewrite ^/ /index.php break;
}

Any help will be appreciated :)

You could use separate location blocks to partition your rewrite logic. For example:

location / {
    try_files $uri $uri/ /index.php;
}
location /extra {
    try_files $uri $uri/ /extra/controller.php;
}
location /adminer {
    try_files $uri $uri/ =404;
}

See this and this for more.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM