如何获得域名表单子域dinamically htaccess?

时间:2017-04-06 16:07:44

标签: apache .htaccess mod-rewrite

我有以下htaccess正在运行:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.([^.]+)\.([^.]+)$ [NC]
RewriteRule ^ %1%{REQUEST_URI} [L]

我有4个域指向同一台服务器(domain.com)

example1.com
example2.com
example3.com
example4.com

当我去

时,实际的htaccess现在
test.example1.com

它将显示目录中的文件

domain.com/test

我想要它。

但我需要实现一项新功能。

所以当我去

test.example1.com

需要转到

domain.com/example1.com/test

同样适用于

test2.example1.com ---->  domain.com/example1.com/test2
test5.example2.com ---->  domain.com/example2.com/test5
test6.example3.com ---->  domain.com/example3.com/test6
test9.example4.com ---->  domain.com/example4.com/test9

它不会重定向,它会重写,我不希望它重定向。

1 个答案:

答案 0 :(得分:1)

您可以使用以下内容替换现有规则:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.([^.]+\.[^.]+)$ [NC]
RewriteRule ^ %2/%1%{REQUEST_URI} [L]