【问题标题】:RedirectMatch adding extra url segmentsRedirectMatch 添加额外的 url 段
【发布时间】:2021-05-25 15:09:29
【问题描述】:

我正在尝试将对我们旧博客的请求重定向到子域上的新 URL。 旧网址看起来像

https://www.website.com/blog-name/post/slug-of-the-title

它需要重定向到

https://stage.website.com/blog-name/slug-of-the-title

我在我的 .htaccess 中使用这个规则

RedirectMatch ^/blog-name/post/(.*)$ https://stage.website.com/blog-name/$1

我被重定向到正确的页面,但我的网址最后有额外的段。喜欢

https://stage.website.com/blog-name/slug-of-the-title/?/blog-name/post/slug-of-the-title

我做错了什么?

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite url-rewriting


    【解决方案1】:

    对于您显示的示例,您能否尝试以下操作。请在测试您的 URL 之前清除您的浏览器缓存。确保将这些规则放在 .htaccess 规则文件的顶部(以防 .htaccess 文件中还有更多规则)。

    RewriteEngine ON
    RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.com$ [NC]
    RewriteRule ^blog-name/post/(.*)/?$ https://stage.website.com/blog-name/$1? [NC,R=301,L]
    

    【讨论】:

    • 这行得通,但它绝对必须高于我的其他规则。非常感谢@RavinderSingh13!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 2018-07-20
    • 1970-01-01
    • 2012-04-08
    • 2019-12-30
    • 1970-01-01
    相关资源
    最近更新 更多