How to create a virtual host from Apache.htaccess?

I am using Apache Friends XAMPP on Windows (local server). I am setting up a virtual host in httpd-vhosts.conf in the Apache configuration directory, e.g.

 NameVirtualHost *:80 <VirtualHost *:80> ServerName test.example.com DocumentRoot "E:\xampp\htdocs\example" </VirtualHost> 

This works great when I view the url

 http://test.example.com 

Is it possible to dynamically create a virtual host from Apache.htaccess?

+6
source share
2 answers

The context for VirtualHost must be server config . See Apache Docs .

This means that the directive can be used in server configuration files (for example, httpd.conf), but not within or containers. In .htaccess in general.

( Directory Dictionary )

+7
source

It seems impossible. Since your .htaccess used only after your host is allowed by the root server configuration files, for example httpd.conf , apache2.conf .

Simply put, .htaccess in the www directory or in its subdirectories will only be processed after the root configuration files are processed.

I mean, you type http://host.name , and apache finds the destination and uses the .htaccess file on the host to perform some operations if necessary.

+6
source

Source: https://habr.com/ru/post/890034/


All Articles