Forums / National / Russian / Разделы в поддомены

Kopusha
#48011 2024-05-07 17:14

How turn page categories in to subdomains (make a virtual redirect from site.com/category to category.site.com)
1. Add the following content to the file functions.custom.php in the system folder:

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
 * Custom functions library
 */
 
defined('COT_CODE') or die('Wrong URL');
 
$subdomain_areas = array('docs', 'tutorials', 'blog');
 
/**
 * Changes  to / for List URLS
 *
 * @param array $args Args passed over from cot_url
 * @return string
 */
 
function list_url_structure(&$args) {
    global $structure, $sys, $subdomain_areas;
 
    $catpath = explode('.', $structure['page'][$args['c']]['path']);
    $root_cat = array_shift($catpath);
 
    if (in_array($root_cat, $subdomain_areas)) {
        // Make the URL absolute and exclude root cat
        $subdomain = $root_cat;
        $path = implode('/', $catpath);
        $url = $sys['scheme'] . '://' . $subdomain . '.' . $sys['domain'] . '/' . $path;
    } else {
        $url = str_replace('.', '/', $structure['page'][$args['c']]['path']).'/';
    }
    unset($args['c']);
    unset($args['e']);
    return $url;
}
 
/**
 * Changes to / for Page URLS
 *
 * @param array $args Args passed over from cot_url
 * @return string
 */
 
function page_url_structure(&$args) {
    global $structure, $sys, $subdomain_areas;
 
    (empty($args['c'])) && $args['c'] = 'system';
 
    $catpath = explode('.', $structure['page'][$args['c']]['path']);
    $root_cat = array_shift($catpath);
 
    if (in_array($root_cat, $subdomain_areas)) {
        // Make the URL absolute and exclude root cat
        $subdomain = $root_cat;
        $path = implode('/', $catpath);
        (!empty($path)) && $path .= '/';
        $url = $sys['scheme'] . '://' . $subdomain . '.' . $sys['domain'] . '/' . $path;
} else {
        $url = str_replace('.', '/', $structure['page'][$args['c']]['path']).'/';
    }
 
    if ($args['id']) {
        $url .= $args['id'];
        unset($args['id']);
    } elseif ($args['al']) {
        $url .= rawurlencode($args['al']);
        unset($args['al']);
    }
    unset($args['c']);
    unset($args['e']);
    return $url;
}

2. Place the file subdomains.dat into the /plugins/urleditor/presets/ folder.

XML/XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
page    m=*                     page?m={$m}
page    c=system&al=*           {$al}{!$c}
page    c=all                   page
page    c=*&al=*                {page_url_structure()}
page    c=*&id=*                {page_url_structure()}
page    c=*                     {list_url_structure()}
tags    a=all&t=*               {$_area}/{$t}{!$a}
tags    a=*&t=*                 {$_area}/{$a}/{$t}
tags    t=*                     {$_area}/{$t}
index   *                       {$_path}
plug    e=*                     {$e}
plug    *                       {$_path}
users   m=details&u=*           users/{cot_url_username()}
users   m=register              {$m}
users   m=profile               {$m}
users   m=passrecover           {$m}
login   *                       {$_area}
message *                       {$_area}
admin   m=*                     admin/{$m}
admin   *                       {$_area}
rss     m=*&c=*                 {$_area}/{$m}/{$c}
rss     m=*&id=*                {$_area}/{$m}/{$id}
rss     c=*                     {$_area}/{$c}
rss     m=*                     {$_area}/{$m}
*       c=*&al=*                {$_area}/{cot_url_catpath()}/{$al}
*       c=*&id=*                {$_area}/{cot_url_catpath()}/{$id}
*       c=*                     {$_area}/{cot_url_catpath()}
*       al=*                    {$_area}/{$al}
*       id=*                    {$_area}/{$id}
*       *                       {$_area}

In the settings of the URLeditor plugin, choose the preset "subdomains".

3. Enable loading of custom functions in config.php:

$cfg['customfuncs'] = true;

After completing the above steps, all your links of the form site.com/docs will be rewritten to docs.site.com.

4. However, for everything to work, you need to add A-records to the domain settings like this:

1
docs.site.com    A    3600    YOUR_IP

Repeat this for each subdomain section. Otherwise, you will encounter an error when opening a link with a subdomain.