简体   繁体   English

我如何设置.htaccess重定向子域到目录

[英]How can i set .htaccess for redirect subdomain to directory

How can i set .htaccess for redirect subdomain to directory 我如何设置.htaccess重定向子域到目录

I have php backend and generate root directory same by username when user created 我有php后端,并在用户创建时通过用户名生成根目录

ex. 恩。 php backend create user xxx my server create /var/www/html/xxx php后端创建用户xxx我的服务器创建/ var / www / html / xxx

this process it's completely abc.com/xxx i have done it. 这个过程完全是abc.com/xxx,我已经完成了。

but... 但...

I want to redirect subdomain to directory 我想将子域重定向到目录

subdomain is dynamically from user 子域是动态来自用户的

xxx.abc.com it's must redirect to abc.com/xxx xxx.abc.com,它必须重定向到abc.com/xxx

how can i set htaccess to do that 我如何设置htaccess来做到这一点

You may use this rule in site root .htaccess: 您可以在网站根目录.htaccess中使用此规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.(abc\.com)$ [NC]
RewriteRule ^ http://%2/%1%{REQUEST_URI} [L,R=301,NE]

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

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