我希望每个子域都充当文件夹,基本上是这样的:
projects.dev -> /
test.projects.dev -> /test
amazing-project.projects.dev -> /amazing-project
我在Virtualhost文件中有这个代码:
<VirtualHost *:80>
ServerName projects.dev
DocumentRoot "D:/xampp/htdocs/projects"
ServerAlias *.projects.dev
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.projects\.dev
RewriteRule ^/(.*)$ "D:/xampp/htdocs/projects/%1/$1" [L,R=301]
</VirtualHost>
然而,当我去&#34; designs.projects.dev&#34;它被重定向到 &#34; designs.projects.dev/index.php/index.php/index.php/index.php /&#34; (/index.php会持续一段时间)。
有谁知道为什么会这样?
感谢。
答案 0 :(得分:0)
您可以使用
<VirtualHost *:80>
ServerName projects.dev
ServerAlias *.projects.dev
DocumentRoot "D:/xampp/htdocs/projects"
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.projects\.dev$ [NC]
RewriteRule ^ /%1%{REQUEST_URI} [L]
</VirtualHost>