[英]Nginx rewrite not working with .php extension
I'm trying to do a url rewrite via this code:我正在尝试通过此代码进行 url 重写:
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.我已将问题缩小到 .php 部分。 Whatever I stick in there to replace it works fine as expected ie .phd .phq .abcdefg ... works fine.
无论我坚持在那里替换它都可以正常工作,即 .phd .phq .abcdefg ... 工作正常。 What do I need to do to make that thing rewrite with that .php extension?
我需要做什么才能用那个 .php 扩展名重写那个东西?
Thanks for your help.谢谢你的帮助。
Reference: How to rewrite old url with a period, question mark and equals in it?参考: 如何用句点、问号和等号重写旧网址?
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.如果您希望
location ~ /canada1/[A-Za-z0-9-_]+/.*
优先于location ~ \\.php$
,那么您需要在配置中将第一个放在第二个之前文件。
For example:例如:
location ~ /canada1/[A-Za-z0-9-_]+/.* {
...
}
location ~ \.php$ {
...
}
See this document for details.有关详细信息,请参阅此文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.