Форумы / National / Russian / Разделы в поддомены

Kopusha
#48011 07.05.2024 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
/**
 * 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.

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:

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.