Under normal circumstances, a virtual host is only allowed to bind one domain name to the root directory.
People who have used emlog should be familiar with the static links in it. It is a typical use of .htaccess files to redirect domain names to web pages.
Use .htaccess to bind domain names to subdirectories. The prerequisite is that your space server must support the rewrite function of apache. Only in this way can .htaccess be used. If your space is a Linux server, it is usually enabled by default. That is, you can bind domain names to subdirectories and multiple sites in one space.
The following is the .htaccess code using link.52ecy.cn bound to the subdirectory link as an example.
<IfModule mod_rewrite.c> RewriteEngineOn RewriteBase/
Bind link.52ecy.cn to the subdirectory link
RewriteCond %{HTTP_HOST} ^link\.52ecy\.cn$ [NC] RewriteCond %{REQUEST_URI} !^/link/ RewriteRule ^(.*)$ link/$1?Rewrite [L,QSA] #You can bind multiple ones. Just repeat the above three lines of code and change the domain name and directory name. That’s it.
If you complete the above steps, your subdomain name should be accessible, but you will find that accessing the main domain name + bound domain name directory on the browser can also be accessed, but this is not what we want. Next, we complete the last step and add an .htaccess file to each bound directory, such as the link directory. htaccess code is as follows:
The following is the .htaccess code taking music.xmgho.com to be bound to the subdirectory music as an example. That is, you can bind domain names to subdirectories and multiple sites in one space. That is, you can bind domain names to subdirectories and multiple sites in one space. That is, you can bind domain names to subdirectories and multiple sites in one space. That is, you can bind domain names to subdirectories and multiple sites in one space.
<IfModule mod_rewrite.c> RewriteEngineOn RewriteBase/ #Only allow access to the bound domain name RewriteCond %{HTTP_HOST} !^link\.52ecy\.cn$ [NC] RewriteRule (.*) http://link.52ecy.cn/$1 [L,R=301] #Processing of directories with the same name under the binding directory RewriteCond %{REQUEST_URI} ^\/link\/ [NC] RewriteCond %{QUERY_STRING} !^(.*)?Rewrite RewriteRule ^(.*)$ /%{REQUEST_URI}/%{REQUEST_URI}/$1?Rewrite [L,QSA]
Conclusion:
Since my server itself supports binding subdomain names to subdirectories, I can’t test it myself. However, I asked a friend to pass the test on Alibaba Cloud’s host. However, Alibaba Cloud limits the number. If you bind more, it will jump to the root directory. From this it seems that not all server providers support this method, and you have to test it yourself.
Finally, the most important point is that your domain name must be resolved to be useful [Laughter~]