apache - RedirectMatch 添加额外的 url 段
问题描述
我正在尝试将对我们旧博客的请求重定向到子域上的新 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
我究竟做错了什么?
解决方案
使用您显示的示例,您能否尝试以下操作。请在测试您的 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]
推荐阅读
- c - A[-1] 是否真的从 A[0] 返回内存中的前一个位置?
- google-ads-api - 我无法将 google ads Api 从旧版本迁移到新版本
- azure - Visual Studio 2019:找不到此本地主机页面(HTTP 错误 404)错误
- python - PyQt5 在不冻结 GUI 的情况下绘制数据的最佳方法
- javascript - 无论如何使用项目外的javascript触发来自客户端应用程序的信号r通知?
- android - Android Gradle Build 花费了太多时间
- php - 在循环PHP中更改变量
- excel - 数天后应用更改的定时炸弹
- deep-learning - 在 Pytorch 模型中可视化渐变
- jwt - NestJS - 护照和策略错误身份验证策略必须有一个名称