本文介绍了重定向子域到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写重写规则,以将子域重定向到子文件夹.
I need to write rewrite rule, to redirect subdomains to sub-folder.
示例: subdomain.domain.io 应该重定向到 domain.io/apps/subdomain ,和 test7.domain.io 应该重定向到 domain.io/apps/test7 ,依此类推.
Example: subdomain.domain.io should be redirected to domain.io/apps/subdomain, and test7.domain.io should be redirected to domain.io/apps/test7 and so on...
在.htaccess文件中,我可以通过以下条件捕获子域:
in .htaccess file I can catch the subdomain via following condition:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.io$
RewriteRule ?
但是如何进行重定向?
谢谢
推荐答案
您可以在网站根目录.htaccess中使用此规则:
You can use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.io$ [NC]
RewriteRule ^ apps/%1%{REQUEST_URI} [L]
-
RewriteCond %{ENV:REDIRECT_STATUS} ^$
用于防止该规则的循环. -
%1
是在第二个RewriteCond
中捕获的子域文本的后向引用. RewriteCond %{ENV:REDIRECT_STATUS} ^$
is used to prevent looping of this rule.%1
is back-reference of subdomain text captured in 2ndRewriteCond
.
这篇关于重定向子域到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!