通过路径更改将子域重定向到域

时间:2014-08-02 06:23:34

标签: wordpress apache .htaccess redirect

我有一个带子域的wordpress多站点安装。我想以下列方式将我的一个子域重定向到域:

  • subdomain.domain.com => domain.com
  • subdomain.domain.com/pages => domain.com/pages
  • subdomain.domain.com/category-X/posts => domain.com/category-X/posts
  • subdomain.domain.com/category-Y/one-old-subcategory/posts => domain.com/one-new-subcategory/posts
  • subdomain.domain.com/categories/subcategories/posts => domain.com/subcategories/posts

我无法找到正确的顺序和重写规则来实现这一目标。 任何帮助将是欣赏。

1 个答案:

答案 0 :(得分:1)

首先重定向特定的所有内容:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteRule ^categories/subcategories/(.*)$ http://domain.com/subcategories/$1 [L,R]

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteRule ^category-Y/one-old-subcategory/(.*)$ http://domain.com/one-new-subcategory/$1 [L,R]

然后其他一切:

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R]