【问题标题】:Nginx parse and redirect to other domainNginx 解析并重定向到其他域
【发布时间】:2018-07-17 06:51:44
【问题描述】:

我想做一些重定向,但为此我需要解析域以发送其他域。

我的旧域名网址是这样的

http://olddomain.com/bg/some-name-part-421.html

http://olddomain.com/bg/some-name-1231.html

http://olddomain.com/bg/some-name-product-name-221.html

我想把这个重定向到喜欢这个

https://www.newdomain.com/magazin/some-name-part.html

https://www.newdomain.com/magazin/some-name.html

https://www.newdomain.com/magazin/some-name-product-name.html

我尝试在服务器块上像这样重定向它们

rewrite ^(/bg/)([a-z-]+-[0-9]+)\.html$ http://www.newdomain.com/magazin/$2 permanent;

这样的重定向效果不好

http://www.olddomain.com/bg/chervena-borovinka-bioherba-3694.html

https://www.newdomain.com/magazin/chervena-borovinka-bioherba-3694

我也想删除数字的最后一部分 - 但我不知道为什么不能正常工作

【问题讨论】:

    标签: .htaccess nginx


    【解决方案1】:

    那是我的.htaccess

    RewriteEngine On
    RewriteRule "^bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "http://newdomain.com/magazin/$1$3" [R]
    

    别忘了设置RewriteBase

    这是代码:https://regex101.com/r/UdMqaQ/3/

    Nginx

    rewrite "^/bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "newdomain.com/magazin/$1";
    

    【讨论】:

    • 重写 "^/bg\/([^0-9]+(?newdomain.com/magazin/$1" ;它在 nginx 上是这样工作的 :)
    猜你喜欢
    • 2014-01-13
    • 2012-11-01
    • 2017-12-13
    • 2015-11-25
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多