Nginx rewrite not working with .php extension

别等时光非礼了梦想. 提交于 2019-12-24 06:36:09

问题


I'm trying to do a url rewrite via this code:

location ~ /canada1/[A-Za-z0-9-_]+/.* {
        rewrite ^/canada1/([A-Za-z0-9-_]+)/.* /atemplates/weather/weather_forecast.php?region=$1&location=$arg_db last;
}

With this url:

/canada1/bc_british_columbia/weather.php?db=90

I've narrowed down the issue to the .php portion. Whatever I stick in there to replace it works fine as expected i.e. .phd .phq .abcdefg ... works fine. What do I need to do to make that thing rewrite with that .php extension?

Thanks for your help.

Reference: How to rewrite old url with a period, question mark and equals in it?


回答1:


Regular expression location blocks are evaluated in order.

If you want location ~ /canada1/[A-Za-z0-9-_]+/.* to take precedence over location ~ \.php$, then you need to place the first one before the second one, in your configuration file.

For example:

location ~ /canada1/[A-Za-z0-9-_]+/.* {
    ...
}
location ~ \.php$ {
    ...
}

See this document for details.



来源:https://stackoverflow.com/questions/40075348/nginx-rewrite-not-working-with-php-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!