Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 重定向匹配添加额外的url段_Apache_.htaccess_Redirect_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache 重定向匹配添加额外的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 我被

我正在尝试将旧博客的请求重定向到子域上的新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

我被重定向到正确的页面,但是我的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]