2015-09-25 39 views
1

我已将博客更改为子域。重定向到子域并更改不同的路径

即www.domain.com/blog - > blog.domain.com

简单规则修正了这个和所有路径:

1 RewriteCond %{HTTP_HOST} !^blog\.camcloud\.com$ [NC] 
2 RewriteRule ^blog$ https://blog.camcloud.com [L,R=301] 
3 RewriteRule ^blog/(.*)$ https://blog.camcloud.com/$1 [L,R=301] 

这此之后适当地移动所有对应的路径。尽管第一个问题是将第2行和第3行合并为1规则吗?我发现只要输入www.domain.com/blog,就不会重定向到blog.domain.com。

另一个问题我已经是我指定的重定向其他路径是这样的:

Redirect 301 /blog/tags/tag/foo https://blog.domain.com/tag/foo 

基本上我删除“标签”,保持路径的其余部分(同时改变课程领域)。但是,随着它留下的“标签”中就有这不起作用:

https://blog.domain.com/tags/tag/foo

我猜是因为以前的规则是什么?同样的事情发生与另一条路径:

Redirect 301 /blog/categories/industry https://blog.domain.com/category/news/industry-news 

目前只有其中的一些,并有完全不同的路径,所以我想一个简单的重定向会工作,但它仍然保持“类别”中的URL。因此,它被重定向,像这样:

https://blog.domain.com/categories/industry

回答

1

你从两个不同的模块mod_rewriteRewriteRule)和mod_aliasRedirect)混合规则。不如把所有的规则使用mod_alias就象这样:

RewriteEngine On 

# specific redirects first 
RewriteRule ^blog/categories/industry/?$ https://blog.domain.com/category/news/industry-news [L,NC,R=301] 

RewriteRule ^blog/tags/(tag/foo/?)$ https://blog.domain.com/$1 [L,NC,R=301] 

# now catch-all rule to redirect everything from /blog to new sub-domain 
RewriteRule ^blog(/.*)?$ https://blog.camcloud.com$1 [L,R=301,NC] 
  • 这是假设/blog/目录没有的.htaccess
  • 确保你测试这个
前清除浏览器缓存
相关问题