How to deploy second-level domain names in the tp5 framework

little bottle
Release: 2023-04-06 08:10:01
forward
6202 people have browsed it

Some projects need to separate the mobile terminal and PC terminal. For example, when visiting xxx.com, the PC terminal page will be displayed. When visiting m.xxx.com, the mobile page is displayed. The main content of this article is to configure the second-level domain name in tp5. I will share it here with friends in need.

You can do this in thinkphp5:

First, modify url_domain_deploy to true in application\config.php, as follows:

'url_domain_deploy' =>  true
Copy after login

Secondly, register in application\route.php Domain name deployment rules.

Where m is the subdomain name, and mobile is the module name. This section indicates that any access with m as the subdomain name will be resolved to the mobile module.

<?phpuse think\Route;
Route::domain(&#39;m&#39;,&#39;mobile&#39;);
Copy after login

If it is configured locally, add

127.0.0.1  xxx.com127.0.0.1  m.xxx.com
Copy after login

in hosts. In addition:
Two virtual hosts must be configured in apache or nginx, one with a domain name of xxx. com, and the other domain name is m.xxx.com. The root directories both point to the public folder, but the port numbers of the two cannot be the same.

Related tutorials: PHP video tutorial

The above is the detailed content of How to deploy second-level domain names in the tp5 framework. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template