问题
I want every subdomain to act as a folder, so basicly:
projects.dev -> /
test.projects.dev -> /test
amazing-project.projects.dev -> /amazing-project
And I have this code in my Virtualhost file:
<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>
However when i go to "designs.projects.dev" it gets redirected to "designs.projects.dev/index.php/index.php/index.php/index.php/" (the /index.php continues for a while).
Does anyone know why this happens?
Thanks.
回答1:
You can use
<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>
来源:https://stackoverflow.com/questions/46872827/why-does-mod-rewrite-redirect-to-index-php-index-php-index-php-etc