How does PHP differentiate between www.domian.com and domain.com?

Source: Internet
Author: User
Tags subdomain subdomain name website ip domian
How does PHP differentiate between www.domian.com and domain.com ?? I applied for the domain name www.domain.com. I want to go to my homepage index. let's make a judgment in php to see if the visitor is from domain.com or www.domain.com. practice has proved that how does $ _ SERVER ['http _ hos php differentiate between www.domian.com and domain.com ??
I applied for the domain name www.domain.com.
I want to make a judgment in index. php on my homepage to see if the visitor is from domain.com or www.domain.com,
Practice has proved that neither $ _ SERVER ['http _ host'] Nor $ _ SERVER ['server _ name'] can work, and the result is messy...

------ Solution --------------------
$ _ SERVER ['server _ name']

This should be okay. I don't know where your questions are.

If not ..

OK,

Use a complicated method.

First use JS to get the address. this is not difficult to directly var url = location. href;
Then return it to the server using AJAX...

You see. is this all right?
------ Solution --------------------
Print_r ($ _ SERVER); // find what you want
------ Solution --------------------
It would be better to retrieve the request address.
------ Solution --------------------
Why cannot I access a domain name without www?
Time added: 2007-3-18
Q: My website is www.abcd.com. Why can I open www.abcd.com but cannot open it directly?

A: By default, only www.abcd.com is bound to the VM. Therefore, abcd.com must be bound before it can be opened.
Procedure:
1. log on to the management center, click business management> domain name service, find the relevant domain name, click manage, then click dns resolution management, and add an ip address,

Add: A record
Host Name: Enter @
Value: enter your VM ip address (which can be found in the VM Management Center)
(Note: This step has generally been automatically completed by our program. if you find that there is a @ record in dns resolution management that points to your ip address, you can skip this step ).


2. click business management> VM Management.
Enter the domain name abcd.com you want to bind in the domain name binding field, and click add.

In this way, you can directly enter abcd.com to open your website.

If you want to bind other domain names, the procedure is the same.




------ Solution --------------------
When doing domain name resolution, you should set a domain name without www. In this way, you can access your website normally when using a domain name without www.

When doing SEO, you need to correctly handle the relationship between domain names with and without www:

The concept of URL standardization. in the search engine's view, URLs with or without www are two different URLs. when they direct to the same website, the search engine will not know which URL should be selected as the primary URL. Therefore, some qualified hosts adopt 301 redirection for URL standardization settings.
If your host does not support 301 redirection, you can use an absolute address link to all the links on the home page.
Domain names with or without www are the same for search engines. you can select either of them as the primary domain names. the primary domain names are used for internal links and links, this will not scatter the prvalues.
How do I set domain names with or without www? Assume that your domain name is xiaojieblog. tk

In the domain name management background, two A records are set during domain name resolution:

Www. xiaojieblog. tk points to the website IP address
Space. xiaojieblog. tk points to the website IP address
Of course, alias resolution is also supported. it is best not to forward URLs.
You can see how to apply for settings for my tk domain name

After the modification takes effect, both www. xiaojieblog. tk and xiaojieblog. tk can work properly on the homepage of my Xiaojie blog.

Www addition or not only depends on the domain name resolution method. For example, if the domain name is baidu.com, it can be resolved to www.baidu.com, xxx.baidu.com, or baidu.com. Therefore, adding or not to www depends on the domain name resolution of the website webmaster. if there is no domain name resolution, you can only access www without adding it. If all of them are parsed, they can be accessed. So these are none of the visitor's business.
------ Solution --------------------
Discussion
This is the case:
In both cases, the root directory is the same.
However, there is a sentence at the bottom of the page to write, so I have to make a judgment,

Domain name judgment
Case With www
Echo str1;
Case without www
Echo str2;

This is the case. the $ _ SERVER ['http _ host'] and $ _ SERVER ['server _ name'] cannot be implemented. I did not expect this. please help me after the test.

------ Solution --------------------
PHP code
  
------ Solution --------------------
Discussion
Use this to try $ _ SERVER ['http _ host'].
$ _ SERVER ['http _ host'] is used to check the access address of a non-current page. if it is empty, it indicates that this page is opened for the first time, you can use $ _ SERVER ['http _ host ']

------ Solution --------------------
To do a website, you must first standardize the website, or calculate the PR value.
------ Solution --------------------
Www.domain.com is only a subdomain name of domain.com, which is similar to abc.domain.com, but most dns servers add this record by default. other subdomain names are not added.

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.