使用htaccess重定向到不同的域和路径


using htaccess to redirect to a different domain and path

尝试301将博客文章从blog.url.com重定向到url.com/blog/*。除了重定向之外,单个帖子的路径也发生了变化,所以我不能使用全局重写规则。

我以为我知道怎么做,但我没有得到预期的结果。这里有一个例子:

redirect 301 /post/1234/post-name https://url.com/blog/post-name

但当我访问url.com/post/1234/post-name时,我最终被重定向到https://url.com/blogpost/1234/post-name

我做错了什么?

事实证明,它必须与我的htaccess中的另一行有关,以重定向根子域:

redirect 301 /

这是一个包罗万象的行为,扰乱了个人重定向。一旦我将根重定向更改为目录索引所在的redirect 301 /index.html,一切都正常工作。

#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / domain name/subfolder/