假设我有上千个我想重定向的旧链接,所有旧链接都像mydomain.com/1234-article-slug-name,新链接像mydomain.com/article-slug-name。
我想配置我的nginx从url中删除文章id并重定向到新的url。
我在apache中找到了我的解决方案,但是我想不出如何在nginx上实现它。
Apache解决方案:
RewriteCond %{REQUEST_URI} [0-9]+- RewriteRule ^(.*)/[0-9]+-(.*)$ $1/$2 [R=301,L]
发布于 2018-09-04 09:11:50
请尝试下面的nginx配置
location / {
if ($request_uri ~ "[0-9]+-"){
rewrite ^/(.*)/[0-9]+-(.*)$ /$1/$2 redirect;
}
}https://serverfault.com/questions/929333
复制相似问题