Use php to parse and implement secondary domain name redirection

不言
Release: 2023-03-23 09:08:02
Original
4418 people have browsed it

The content of this article is to use PHP parsing to implement secondary domain name redirection. Friends in need can refer to the content of the article

After registering a domain name, it is often necessary to implement different secondary domain names Access different nodes of the site

General domain name registration agencies provide cname resolution methods, and you can define second-level domain names to different IPs.


For example

www.abc.com points to the main node 1.2.3.4

bbs.abc.com points to 1.2.3.4/bbs Or another ip

But if the website rents hosting space, a painful problem will come

The website only has one IP, and the website is a rented hosting space, not Hosting cannot directly set different access nodes. Hosting space can only set an entrance URL provided by the space provider

That is, the website has only one entrance, and the second-level domain name cannot be directly resolved to different subdirectories


Using PHP code can solve this problem,

Ideas

1. Define different second-level domain names, pointing to the same website entrance

2. On the first page index.php of the website entrance, determine the domain name entered by the user, and then redirect to the website sub-contact


php global variable $_SERVER[ 'HTTP_HOST'], you can get the domain name string currently visited by the user, query the sub-domain name strings defined by yourself, and then use the header function to redirect to different pages

The code is as follows

if( strpos($_SERVER['HTTP_HOST'],"china") !== false ) // Be sure to use !== but not !=, otherwise false and 0 cannot be distinguished
{//
header('location:/china/indexphp');
}elseif( strpos($_SERVER['HTTP_HOST'],"bbs") !== false )
{
header('location :/bbs/forum.php');
}
else
{//Display homepage
header('location:/templets/default/index.htm');
}

Related recommendations:

A piece of code that uses PHP to parse JSON data

##Uses PHP to parse RDDL documents

The above is the detailed content of Use php to parse and implement secondary domain name redirection. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template