简体   繁体   中英

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:

blog.test.com/12/09/test-2 to test.com/blog/test-2 How it possible? I tried this

or just simply redirect all the blog.test.com with whatever query they have to the new page?

blog.test.com/whatever?whatever to test.com/blog

You can use this code in your DOCUMENT_ROOT/.htaccess file of test subdomain:

RewriteEngine On
RewriteBase /

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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