Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Virtual Host from Apache .htaccess?

I am using Apache Friends XAMPP in Windows (Local Server). I setup the virtual host in httpd-vhosts.conf in an Apache configuration directory like this

NameVirtualHost *:80

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

This works fine when I browse the URL

http://test.example.com

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

like image 647
Madan Sapkota Avatar asked Jun 08 '11 07:06

Madan Sapkota


People also ask

Is Apache a virtual host?

Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.


2 Answers

The context for VirtualHost has to be server config. See the Apache docs.

This means that the directive may be used in the server configuration files (e.g., httpd.conf), but not within any or containers. It is not allowed in .htaccess files at all.

(Directive Dictionary)

like image 56
Matthias Avatar answered Sep 20 '22 09:09

Matthias


It seems to be impossible. Because your .htaccess is used only after your host is resolved by root configuration files of a server like httpd.conf, apache2.conf.

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

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

like image 42
Dmitri Gudkov Avatar answered Sep 22 '22 09:09

Dmitri Gudkov