Good afternoon, how to implement an unlimited number of domains under. Htacces? There are such thoughts, but I cannot implement it myself. Suppose there is a site site.ru and it under the domain name.site.ru. In the directive under the domain there is a file index.php with the code

if (isset($_GET['name'])) {$name= $_GET['name'];} echo $name; 

and now when entering the site name.site.ru/index.php?name=petya , then Petya will be displayed. How to achieve the same inscription by clicking on the link petya.site.ru using the .htacces file?

  • Dear hashcode correct .htaccess in the title - Sergey
  • You are doing the wrong things: this is called subdomains. There are articles on automatic subdomains, moreover, such a topic has already existed - look, there is an answer already. - Sergey

3 answers 3

Something like

 RewriteCond %{HTTP_HOST} ^([a-zA-Z]+\.)?site\.ru RewriteRule ^(.*) index.php?name=%1 [L] 
  • did not work .. - dogmar
  • one
    And it will not work. Your browser needs to know where to send requests. And for this, he must request an IP from the address petya.test.ru. But there is no such information in the CSN, therefore it will not work. - Fucking Babai
  • @ Yoharny Babai that is, in theory, if you still create a subdomain, will it work? - Ozim

In virtual hosts register IMHO

 <VirtualHost *:80> ServerName subdomain.host.ru ServerAdmin webmaster@localhost DocumentRoot /home/user/www/host/www <Directory /home/user/www/host/www/> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost> 
  • And about the CSN forgot? - Fucking Babai

Without the settings of Apache and records in NS can not do. But this is done only once.

 <VirtualHost YOUR_IP:80> DocumentRoot "/home/user/www" ServerName "test.ru" ServerAlias "test.ru" "*.test.ru" ScriptAlias /cgi/ "/home/user/www/cgi/" ScriptAlias /cgi-bin/ "/home/oser/www/cgi-bin/" </VirtualHost> 

and add a record of type "A" in NS records:

 * A YOUR_IP 

further in .htaccess:

 RewriteEngine On RewriteCond %{HTTP_HOST} ^([a-zA-Z]+\.)?test\.ru RewriteRule ^(.*) index.php?name=%1 [L] 

From this point on, all queries of the type: petya | vasya | ya | supermod | test | durak.test.ru

The script will come index.php? Name = petya | vasya | ya | supermod | test | durak

And there you yourself know what to do with them.

  • My site is hosted to add settings to Apache, do you need to communicate with support or is there any file on FTP? or whatever, what actions should be to add settings in Apache - dogmar
  • @dogmar, on many hosts there are options "create a subdomain", and even "auto subdomains" (I have this on <a href=" jino.ru"> Gino </ a >). MB it will be easier for you to ask in technical support? They may be banned from you at all. - Sh4dow
  • I'm on agave, and I have to add a subdomain, but again the Apache remains in question. NS is also not clear abbreviation - dogmar
  • If it is possible to add a subdomain, then the Apache and National Assembly will tune themselves ... But you will have to manually create subdomains for each user. And try to add a subdomain named "*" (asterisk). - Fucking Babai
  • It is a Kalhoz manually. My users register every day .. - dogmar