1

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 Answer 1

0

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>
Sign up to request clarification or add additional context in comments.

4 Comments

The server doesn't start when I use VirtualDocumentRoot
What is your Apache version?
Apache 2.4.27 (Win 32)
Oh VirtualDocumentRoot needs 2.4. let me edit it accordingly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.