本文介绍了Nginx重写不适用于.php扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下代码重写网址:

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;
}

使用此网址:

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

我已经将问题缩小到.php部分.无论我坚持在那里替换它的任何东西都可以按预期工作,即.phd .phq .abcdefg ...可以正常工作.我该怎么做才能用.php扩展名重写该内容?

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?

感谢您的帮助.

参考:如何用句点,问号和等号重写旧网址?

推荐答案

正则表达式位置块按顺序求值.

Regular expression location blocks are evaluated in order.

如果您希望location ~ /canada1/[A-Za-z0-9-_]+/.*优先于location ~ \.php$,则需要在配置文件中将第一个之前放置在之前.

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.

例如:

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

有关详细信息,请参见本文档.

See this document for details.

这篇关于Nginx重写不适用于.php扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:53