通过路径更改将子域重定向到域
问题描述:
我有一个带有子域的wordpress多站点安装。我想通过以下方式将我的子域之一重定向到域:
I have a wordpress multisite installation with subdomains. I want to redirect one of my subdomain to domain in the following manner:
- 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
- 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
我找不到正确的顺序并重写规则来实现这一目标。
任何帮助将不胜感激。
I couldn't find correct order and rewrite rules to achieve that. Any help would be appreciate.
答
首先重定向所有特定内容:
First redirect everything that's specific:
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]