Configuration of multiple sites with one IP address-php Tutorial

Source: Internet
Author: User
I want to resolve two domain names to the same IP address of 209.221.156.243. However, after configuring apache, the two domain names always point to the same site.
The configuration code is as follows:
NameVirtualHost 209.221.156.243: 80


ServerName xx.com
DocumentRoot d:/aa
ErrorDocument 404/404 .html
ErrorLog "| bin/rotatelogs.exe-l d:/aa/logs/errorlog. % Y-% m-% d-% H _ % M _ % S. log 86400"
CustomLog "| bin/rotatelogs.exe-l d:/aa/logs/access % Y-% m-% d. log 86400" combined
RewriteEngine on
RewriteCond % {HTTP_HOST} ^ xx.com [NC]
RewriteRule ^ (. *) $ http://www.xx.com $1 [L, R = 301]
RewriteEngine On
RewriteCond % {REQUEST_METHOD} ^ TRACE
RewriteRule. *-[F]


ServerName yy.com
DocumentRoot d:/bb
ErrorDocument 404/404 .html
ErrorLog "| bin/rotatelogs.exe-l d:/bb/logs/errorlog. % Y-% m-% d-% H _ % M _ % S. log 86400"
CustomLog "| bin/rotatelogs.exe-l d:/bb/logs/access % Y-% m-% d. log 86400" combined
RewriteEngine on
RewriteCond % {HTTP_HOST} ^ yy.com [NC]
RewriteRule ^ (. *) $ http://www.yy.com $1 [L, R = 301]
RewriteEngine On
RewriteCond % {REQUEST_METHOD} ^ TRACE
RewriteRule. *-[F]


Access yy.com but access xx.com! I have found a lot on the Internet, but I have not found the correct solution. hope experts can help me.


Reply to discussion (solution)

How can I identify the same port?

How can I identify the same port?
If the domain name is a different port, it must be followed by a port number to access it!

I have not found any writing problems.
It may be related to the apache version or other settings.

I have not found any writing problems.
It may be related to the apache version or other settings.
The strange thing is that after I configure the second one to www.yy.com
When I access www.yy.com, I can access the program under bb correctly.
However, yy.com without www still accesses the program under aa, that is, www.xx.com!

Reference the reply from xuzuning on the third floor: I did not find any problem in writing the code.
It may be related to the apache version or other settings.
The strange thing is that after I configure the second one to www.yy.com
When I access www.yy.com, I can access the program under bb correctly.
However, yy.com without www still accesses the program under aa, that is, www.xx.com!
After configuring the second ServerName to www.yy.com

According to the rule, yy.com is a domain, and www.yy.com is a domain name.
It may be related.
You can try to comment out the global Section 1

Er, single point of access
ServerName must be a domain name
The reason may be that your RewriteRule is for www.

Thank you two for solving the problem. It is indeed related to domain name rules and 301 redirection rules. Close the post.

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.