本文介绍了如何用句号,问号和等号重写旧的url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的旧网站的网址是这样的:
My old website has url's like this:
/canada1/bc_british_columbia/weather.php?db=90
我正在尝试像这样使用Nginx重写:
I'm trying to use an Nginx rewrite like this:
location ~ /canada1/([A-Za-z0-9-_]+)/(.*) {
rewrite ^/canada1/([A-Za-z0-9-_]+)/(.*)$ /atemplates/weather/weather_forecast.php?region=$1&location=$2 last;
}
我可以获得$ 1的罚款,但是$ 2似乎无法弄清楚正则表达式,因此我可以在网址末尾得到"90"部分.我想我想知道用(.*)代替什么.任何帮助表示赞赏.
I can get the $1 fine but the $2 I can't seem to figure the regex out so I can get that "90" portion at the end of the url. I guess I'm wondering what to replace that (.*) with. Any help appreciated.
推荐答案
请尝试以下代码,
server {
...
location ~ /canada1/[A-Za-z0-9-_]+/.* {
rewrite ^/canada1/([A-Za-z0-9-_]+)/.* /atemplates/weather/weather_forecast.php?region=$1&location=$arg_db last;
}
...
}
编辑:请确保上述位置在位置〜.php块之前,因为具有正则表达式的位置将按顺序处理,并执行第一个匹配的位置,在此处阅读.
Edit: Make sure the above location is before location ~ .php block, as location with regular expression are processed in order, and the first matching one is executed, Read Here.
这篇关于如何用句号,问号和等号重写旧的url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!