Using. htaccess in apache to implement a wildcard second-level domain name

Source: Internet
Author: User

Resolve a wildcard domain name * .xxxx.com to your space IP address. An independent IP Virtual Host supports wildcard resolution and can access the website without binding a domain name. This is called a wildcard domain name, such as Sina Blog and 163 blog.

1. Resolve the domain name * .xxxx.com to your space IP address. The independent IP Virtual Host supports wildcard resolution and can access the website without binding a domain name.
2. Create the bbs and home directories, upload the CMS to the root directory, upload the forum to the bbs directory, and upload the ucenterHome to the home directory.
3. Open notepad and copy the following code, save it as a. htaccess file, and upload it to the root directory.
The content of the. htaccess file is as follows: (take the 111cn.com domain name as an example)
RewriteEngine on
DirectoryIndex index. php index.html index.htm
# Allow www.xxx.cn to access the root directory CMS
RewriteCond % {HTTP_HOST} ^ www.111cn.com $
RewriteCond % {REQUEST_URI }! ^/
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule ^ (. *) $/$1
RewriteCond % {HTTP_HOST} ^ www.111cn.com $
RewriteRule ^ (/)? $/Index. php [L]
# Enable home.xrnic.cn to access the home Directory UcenterHome
RewriteCond % {HTTP_HOST} ^ home.111cn.com $
RewriteCond % {REQUEST_URI }! ^/Home/
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule ^ (. *) $/home/$1
RewriteCond % {HTTP_HOST} ^ home.111cn.com $
RewriteRule ^ (/)? $ Home/index. php [L]
# Access bbs.xrnic.cn to the bbs directory Forum
RewriteCond % {HTTP_HOST} ^ bbs.111cn.com $
RewriteCond % {REQUEST_URI }! ^/Wap/
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule ^ (. *) $/bbs/$1
RewriteCond % {HTTP_HOST} ^ bbs.111cn.com $
RewriteRule ^ (/)? $ Bbs/index. php [L]
Using the above method, you can create N websites in one space, or point other top-level domain names to sub-directories to create multiple websites in one space.

First :! (Exclamation point) indicates no. For example, if a condition is used to determine whether the previous page URL to access this page contains the sex character, it can be used as follows: RewriteCond % {HTTP_REFERER }! (Sex)
Second: <is smaller than the meaning, TestString <CondPattern.
Third:> is greater than the meaning, TestString <CondPattern.
Fourth: = equal meaning. <,>, = three <,>, = used in common programming languages.
Fifth:-d is a directory. You can determine whether TestString is not a directory as follows :! -D
Sixth:-f is a file. You can determine whether TestString is not a file as follows :! -F
7. Check whether-s is a normal file with a size. You can determine whether TestString is not a normal file with a size as follows :! -S
Eighth:-l is a shortcut file. You can determine whether TestString is not a shortcut file as follows :! -L
Ninth:-x is a file and executes the permission again. You can determine whether TestString is not a file and execute the permission again as follows :! -X
Tenth:-F checks whether TestString is a legal file and uses the access control currently set in the server range for access. This check is completed through an internal subrequest, so you need to use this function with caution to reduce server performance.
11th:-U checks whether TestString is a valid URL and uses the access control currently set in the server range for access. This check is completed through an internal subrequest, so you need to use this function with caution to reduce server performance.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.