问题描述
我们正在转换供应商以进行属性搜索,并且每个URL的格式略有不同.我们已经为40,000多个URL编制了索引,并希望将301用户重定向到新URL.
We are switching vendors for our property searches and each one formats the URLs a little bit differently. We already have 40,000+ URLs indexed and want users to be 301 redirected to the new URL.
URL中的唯一区别是从下划线到连字符,从/idx/到/property/的切换.
The only difference in the URLs is a switch from underscores to hyphens, and from /idx/ to /property/.
这是旧的网址: http://www.mysite.com/idx/mls-5028725-10425_virginia_pine_lane_alpharetta_ga_30022
这是新的网址: http ://www.mysite.com/property/mls-5028725-10425-virginia-pine-lane-alpharetta-ga-30022
有什么想法如何重定向所有这些URL,而又不知道40,000个以上的URL中的每个URL是什么?
Any ideas how to redirect all of these URLs without knowing what every one of the 40,000+ URLs are?
谢谢,基思
推荐答案
我自己更喜欢ngx_lua模块.
I prefer the ngx_lua module myself.
location /idx/ {
rewrite_by_lua '
local tempURI, n = ngx.re.gsub(ngx.var.uri, "_", "-")
local newURI, m = ngx.re.sub(tempURI, "/idx", "/property", "i")
return ngx.redirect(newURI, ngx.HTTP_MOVED_PERMANENTLY)
';
}
第一行(gsub)将所有"_"更改为-"
First line (gsub) changes all "_" to "-"
第二行(sub)将第一个"/idx"更改为"/property"
Second line (sub) changes first "/idx" to "/property"
第三行很明显
这篇关于Nginx从旧URL重定向到新URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!