Url redirection subdirectory to subdomain

2019-06-06 10:49发布

问题:

I am using php. and i want to redirect subdirectory to subdomain and subdirectory of subdirectory to subdomain directory.

For example : if i have url like http://www.test.com/test1/

then it should be redirect to http://test1.test.com/

and second if i have url like this http://www.test.com/test1/test2/

then it should be redirect to http://test1.test.com/test2/

Any one have idea how to do this.

Thanks in advance

回答1:

can do in .htaccess with something like..

RewriteEngine On
RewriteRule ^([^/]+)/(.*)$ http://$1.test.com/$2 [R,L]