Apache 重定向匹配添加额外的url段
我正在尝试将旧博客的请求重定向到子域上的新url。 旧的url看起来像Apache 重定向匹配添加额外的url段,apache,.htaccess,redirect,mod-rewrite,url-rewriting,Apache,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我正在尝试将旧博客的请求重定向到子域上的新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://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
我被重定向到正确的页面,但是我的URL在末尾有额外的段。像
https://stage.website.com/blog-name/slug-of-the-title/?/blog-名称/职位/标题的片段
我做错了什么?对于您展示的样品,请您尝试以下内容。请在测试URL之前清除浏览器缓存。确保将这些规则保留在.htaccess规则文件的顶部(以防.htaccess文件中还有更多规则)
这是可行的,但它肯定要高于我的其他规则。非常感谢@RavinderSingh13!
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.com$ [NC]
RewriteRule ^blog-name/post/(.*)/?$ https://stage.website.com/blog-name/$1? [NC,R=301,L]