ThinkPHP5 multi-template configuration secondary domain name

Now a lot of projects have the PC side and mobile terminal, PC and mobile end are respectively in different modules, and "www" two domain names directly access the PC end (index module), if you want to access the mobile end " .com the WWW. Domain Name / Mobile ", so that the domain name is too long, here I teach you a way to shorten the domain name.

 

ready

ThinkPHP supports full domain, subdomain and deployment of IP routing and binding function, but also can play a role in simplifying the URL.

To enable the deployment of domain routing function, you first need in config.php open:

// domain deployment 
'url_domain_deploy' => to true ,

Custom domain name rules support the deployment of two ways: dynamic registration and configuration definitions

 

Dynamic registration

Can be applied in a public document or application \ route.php deploy rules dynamically register a domain name, for example:

<?php
use think\Route; Route::domain('m','mobile');

Such access "m. Domain name .com" you can directly access the mobile template

When bound to add support default parameters, such as:

// m subdomains bind to the mobile module 
Route :: domain ( 'm', 'mobile var = thinkphp?');

In addition to binding to the module, but also implicitly introduced to a $_GET['var'] = 'thinkphp' variable.

Support direct binding to the controller, for example:

// m subdomains bind to index the mobile module controller 
Route :: domain ( 'm', 'mobile / index');

If your domain name suffix is rather special, for example, com.cnor net.cn like the domain name, you need to configure the config.php:

'url_domain_root'=>'thinkphp.com.cn'

 

Configuration defines the way

In addition to the dynamic registration, also supports direct application \ route.php deployment rules (Route Profile) defined in the domain name, for example:

<? PHP
 use Think \ the Route; 
the Route :: Domain ( 'Mo', 'Mo' );
 return [
     // binding domain to the module 
    '__domain__' => [
         'API' => 'API', 
        'm' = > 'Mobile', 
        'WWW' => 'index', 
    ] , 
];

 

Binding routing rules

The domain name can be bound to a list of specified routing rules, such as:

:: Domain Route ( 'Blog', [
     // dynamically register the domain name routing rules 
    ': id '=> [' blog / read ', [' method '=>' GET '], [' id '=>' \ + D ']], 
    ': name '=>' Blog / Read ', 
]);

If you use the profile configuration, you can in the following manner:

return [
     '__domain __' => [
         'Blog' => [
             // dynamically registered domain routing rule 
            ': id' => [ ' blog / read', [ 'method' => 'GET'], [ 'id' => '\ + D']], 
            ': name' => 'Blog / Read', 
        ] , 
    ] ,
     // the following are other routing rules defined 
]





Guess you like

Origin www.cnblogs.com/bushui/p/12098138.html