Some time ago, Xi'an SEO shared an article about the method of "(personal test) AliCloud free virtual host subdirectory binding secondary domain name". Today Mo Xiaoyu Blog
See“ Method of binding multiple domain names to create multiple websites on the virtual machine of the World Wide Web ”, bind different independent domain names to different subdirectories, which means that a virtual host has multiple independent websites and independent domain names.
Method of binding multiple domain names to create multiple websites on the virtual machine of the World Wide Web
Bind multiple domain names to create multiple websites on the virtual machine of the World Wide Web as follows:
First, modify htaccess in the root directory of the host (if not, create a new one)
In the htaccess file Topmost
Add the following code:
- RewriteEngine On
- RewriteBase /
-
- RewriteCond %{HTTP_HOST} ^(www\.)wosn\.net$ [NC]
- RewriteCond %{REQUEST_URI} !^/ wosn/
- RewriteCond %{REQUEST_FILENAME} !- f
- RewriteCond %{REQUEST_FILENAME} !- d
- RewriteRule ^(.*)$ wosn/ $1
- RewriteRule ^(/)$ wosn/index.php [L]
-
- RewriteEngine On
- RewriteBase /
-
- RewriteCond %{HTTP_HOST} ^(www\.)abcd\.com$ [NC]
- RewriteCond %{REQUEST_URI} !^/ aaa/
- RewriteCond %{REQUEST_FILENAME} !- f
- RewriteCond %{REQUEST_FILENAME} !- d
- RewriteRule ^(.*)$ aaa/ $1
- RewriteRule ^(/)$ aaa/index.php [L]
The meaning of the above code is to Www.wosn.net or wosn.net
Bind to the wosn
folder; take Www.abcd.com or abcd.com
Bind to the aaa
folder; You can modify it accordingly. If you need to build a third website, just add another paragraph.
Secondly, solve the wosn.net/wosn problem by visiting www.wosn.net
After adding the above code, you will find that the content of www.wosn.net can also be accessed through wosn.net/wosn, which is not what we want to see, so we need to modify the htaccess file in the wosn and aaa folders respectively, and add the following code (taking the wosn folder as an example):
- RewriteEngine On
- #No access through domain names other than this website
- RewriteCond %{HTTP_HOST} !^ (www.)wosn.net$ [NC]
- RewriteRule ^.*$ [L,r=404]
If it is an aaa folder, you can modify its domain name accordingly.
Finally, bind the two domain names to the virtual host.
The domain name and virtual machine binding tutorial can be referred to“ (Pro test) AliCloud free virtual host subdirectory is bound to the secondary domain name ”Article.
So far: binding multiple domain names to create multiple websites on the virtual machine of the World Wide Web has been fully realized. If there is any problem during the operation, please leave a message below to discuss.
Attachment: Detailed configuration of. htaccess