Home Backend Development PHP Tutorial PHP怎么区别www.domian.com和 domain.com的差异?

PHP怎么区别www.domian.com和 domain.com的差异?

Jun 13, 2016 pm 01:48 PM
com server

PHP如何区别www.domian.com和 domain.com的差异??
我的申请了www.domain.com这个域名。
我想在我的首页index.php中做一个判断,看看访客是从domain.com来的,还是www.domain.com来的,
实践证明,$_SERVER['HTTP_HOST']和$_SERVER['SERVER_NAME']都不行,刷出来是乱七八糟的结果。。。

------解决方案--------------------
$_SERVER['SERVER_NAME']

这个应该是没什么问题的吧. 不知道你的疑问在哪里

万一不行..

OK,

用复杂的办法吧.

先用JS得到地址.这个不难 直接 var url=location.href;
然后用AJAX回传给服务器...

您看.这样可以吗?
------解决方案--------------------
print_r($_SERVER);//找找你想要的
------解决方案--------------------
去取请求地址会好点吧
------解决方案--------------------
为什么不加www的域名不能访问?
添加时间:2007-3-18 
问:我的网站是www.abcd.com,为何输入www.abcd.com可以打开,而直接输入abcd.com打不开?

答:虚拟主机开通的时候默认只绑定了www.abcd.com,所以abcd.com需要绑定后才能打开。
操作步骤:
1.登录管理中心,点业务管理>域名服务,找到相关的域名,点管理,然后点 dns解析管理, 点 增加ip,

添加: A 记录
主机名: 填入 @
对应值: 填入你的虚拟主机ip (在 虚拟主机管理中心可以查到)
(注意: 这一步一般已经由我们的程序自动完成了,如果您发现在:dns解析管理中 有一个@记录,指向了你的ip,你就可以跳过这一步了)。


2.点业务管理>虚拟主机管理 
在域名绑定一栏 输入您想绑定的域名abcd.com,然后点添加就行了。

这样,您就可以直接输入abcd.com打开你的网站了。

如果你想绑定其他的域名,其步骤也是一样的。




------解决方案--------------------
在做域名解析时,应该设置一个不带www的域名。这样,当用户使用不带www的域名时,可以正常访问你的网站。

做SEO时需要正确处理带www和不带www域名的关系:

URL标准化的概念,在搜索引擎看来,带www和不带www的URL是不同的两个URL,当它们指向同一个网站时,会让搜索引擎不懂应该选择哪一个URL作为主要的。所以,部分符合条件的主机采用301重定向进行URL 标准化设置。 
如果你的主机不支持301重 定向,把首页的所有链接采用绝对地址的链接形式也可以很好解决这个问题。 
带www和不带www的域名对搜索引擎是同等的,任意选择其中一个作为主域名,在内部链接和友情链接时,都使用主域名,这样不会使PR值分散。 
带与不带www的域名如何设置?假设你的域名是 xiaojieblog.tk

在域名管理后台,域名解析时,设置两个A记录:

www.xiaojieblog.tk 指向网站IP 
空格.xiaojieblog.tk 指向网站IP 
当然也可以别名解析 ,最好不要 url转发 
可以看看我的tk域名如何申请设置的

生效后,通过 www.xiaojieblog.tk 和 xiaojieblog.tk 都可以正常我的 小杰博客 首页了。

www加不加只是取决于改域名解析方式。比方说域名为baidu.com,他可以解析为www.baidu.com,也可以是xxx.baidu.com,也可以直接为baidu.com的解析。所以,加不加www都取决于网站站长的域名解析,有些没有解析的,就只能加www访问,不加就访问不了。如果都解析了,就都能访问。所以这些都不关访问者的事情。
------解决方案--------------------

探讨
是这种情况:
带不带www两种情况,都指向同一个根目录。
但是,页面底部有一句话要写,所以我要做个判断,

判断域名
case 有www
echo str1;
case 没有www
echo str2;

就是这样,$_SERVER['HTTP_HOST']和$_SERVER['SERVER_NAME']做不到,完全在我预料之外,请实际测试过后帮帮我吧。

------解决方案--------------------
PHP code

<?php $wz_thisurl=$wz_haha='';
$wz_thisurl=$_SERVER['SERVER_NAME'];
$wz_haha=(strstr($wz_thisurl,'www'))?'带www':'不带www';
echo $wz_haha;
?>
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨
用这个试一试$_SERVER['HTTP_HOST']
$_SERVER['HTTP_HOST']是用来看上一次非本页面的访问地址的,如果是空,那么说明第一次打开的就是这个页面,所以楼主用$_SERVER['HTTP_HOST']看看

------解决方案--------------------
做网站首先要进行网址规范化,要不怎么统计PR值
------解决方案--------------------
www.domain.com只是domain.com其中一个子域名,跟abc.domain.com差不多,只不过大部分dns都会默认添加这个记录,其他子域名不会添加
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

How to install, uninstall, and reset Windows server backup How to install, uninstall, and reset Windows server backup Mar 06, 2024 am 10:37 AM

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

What is the difference between comcn and com What is the difference between comcn and com May 12, 2023 pm 04:08 PM

The difference between comcn and com: 1. There are differences between comcn and com in terms of meaning, but there is no difference in access speed; 2. comcn is an international domain name and is a global top-level domain name for use by commercial institutions, while cn is a Chinese company domain name , domestic commercial institutions, domestic domain names, only enterprises can register; 3. The search priority is that cn will search for .cn first. After finding the .cn server, the .cn server will then search for .com; 4. cn is provided by cnnic China Internet Center Management, com's management organization is abroad.

Windows Server 2025 preview version welcomes update, Microsoft improves Insiders testing experience Windows Server 2025 preview version welcomes update, Microsoft improves Insiders testing experience Feb 19, 2024 pm 02:36 PM

On the occasion of releasing the build 26040 version of Windows Server, Microsoft announced the official name of the product: Windows Server 2025. Also launched is the Windows11WindowsInsiderCanaryChannel version build26040. Some friends may still remember that many years ago someone successfully converted Windows NT from workstation mode to server mode, showing the commonalities between various versions of Microsoft operating systems. Although there are clear differences between Microsoft's current version of the server operating system and Windows 11, those who pay attention to the details may be curious: why Windows Server updated the brand,

How to modify the Nginx version name to disguise any web server How to modify the Nginx version name to disguise any web server May 14, 2023 pm 09:19 PM

How to modify the default name of nginx, you can disguise it a little, or you can install Tip: Generally, modifications are made before nginx is compiled. After modification, the code needs to be recompiled as follows: scr/core/nginx.conf#definenginx_version"1.4.7"#definenginx_ver"nginx/"n

Microsoft releases Windows Server vNext preview version 25335 Microsoft releases Windows Server vNext preview version 25335 Jan 10, 2024 am 08:49 AM

While Microsoft released the Win11 preview update for the desktop, today it also released the Windows Server Long Term Service Channel (LTSC) preview Build 25335. As usual, Microsoft did not publish a complete change log, or even provide a corresponding blog post. Microsoft has adjusted the Windows Server preview version update log to make it the same as the Canary channel version. If no new content is introduced, the official blog post will not be posted. Note from IT Home: The server brand has not been updated and is still Windows Server 2022 in the preview version. In addition, Microsoft calls these versions Windows Server vNext instead of the Windows version that is already on the market.

Microsoft releases Windows Server 26080 preview update: Fixes Feedback Hub failure Microsoft releases Windows Server 26080 preview update: Fixes Feedback Hub failure Mar 14, 2024 pm 07:11 PM

IT House reported on March 14 that in addition to the Windows 11 Build 26080 preview update for the desktop, Microsoft also updated and launched the Windows Server Build 26080 preview update. As the latest preview version of the upcoming Windows Server Long Term Servicing Channel (LTSC), Windows Server Build 26080 provides Data Center Edition and Standard Edition, and users can choose desktop experience and Server Core installation options. This release also includes an annual channel for container hosts, and an Azure release specifically for virtual machine evaluation. IT House queries X social media. User feedback clicks the Copilot button in the lower right corner.

What is the matching logic of Server and Location in Nginx? What is the matching logic of Server and Location in Nginx? May 12, 2023 am 11:10 AM

Server matching logic When nginx determines which server block to execute a request, it mainly focuses on the listen and server_name fields in the server block. The listen command listen field defines the IP and port of the server response. If the listen field is not explicitly configured, the default listening 0.0.0.0:80 (root) or 0.0.0.0:8080 (non-root) listen can be configured as: a combination of ip and port, a single ip, listening on port 80 by default, a single port, and listening on all ip interfaces by default A unixsocket path where the last entry is usually only used in different

See all articles