简体   繁体   English

如何使用htaccess将带有子目录的子域重定向到新的url

[英]how to redirect a subdomain with child directory to new url using htaccess

I have a old website which used subdomains for each pages, i'm moving to new site and want to redirect the most of the links to the new pages. 我有一个旧网站,每个页面都使用子域,我要移到新站点,并希望将大多数链接重定向到新页面。

I searched a lot but didn't find anything. 我搜索了很多,但没有找到任何东西。

For instance i will be redirect this url to this: 例如,我将这个URL重定向到这个:

blog.test.com/12/09/test-2 to test.com/blog/test-2 How it possible? blog.test.com/12/09/test-2到test.com/blog/test-2怎么可能? I tried this 我试过了

or just simply redirect all the blog.test.com with whatever query they have to the new page? 还是只是将所有对他们具有任何查询的blog.test.com重定向到新页面?

blog.test.com/whatever?whatever to test.com/blog blog.test.com/whatever?无论要测试什么

You can use this code in your DOCUMENT_ROOT/.htaccess file of test subdomain: 您可以在test子域的DOCUMENT_ROOT/.htaccess文件中使用以下代码:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(blog)\.(test\.com)$ [NC]
RewriteRule ^\d{2}/\d{2}/(.+)$ http://%1/blog/$1 [L,R=302]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM