Ant classification information system 6.0 generates city directory

In the actual use of more than 6.0 versions of ant classification information system, many users will put the city directory generated by the system under the root directory, with more than 300 city directories. Later, if they want to modify a function file, it is very troublesome to find it, and the directory structure of the whole website is also very chaotic. To solve this problem, you can add functions and remove the city directory.
The function of files under the city directory is mainly to assign the city ID. as long as the city ID is automatically obtained according to the relevant access URL, the function of files under the city directory can be realized
This article is based on category. In the root directory PHP file classification function modification as an example to provide modification ideas
1. First, turn on the phonetic pseudo static function of classification. The modification is only for the phonetic pseudo static function

2. When accessing the classification, the format is domain name / city directory name / classification directory Pinyin pseudo static/



The format of the access example is as follows. Note that it ends with "/". If it is a terminus, there is no intermediate city directory name

When there is no city directory, it is necessary to distinguish between the name of the classification or the name of the city sub station behind the domain name when accessing the master station classification and the city home page Pinyin pseudo static, such as
House rental and sale access URL http://192.168.0.137/fang/
Wuhan Branch homepage access URL http://192.168.0.137/wh/
For the convenience of differentiation, it is stipulated that the following access classification ends with "/", and urban sub stations do not end with "/"
Please also modify the sub station selection. When selecting the sub station, the link of the sub station shall not end with "/", but the link on the home page of the navigation
3. Set APACHE pseudo static rules

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!store|space|news)(.+[\/]?.+)/$ category\.php\?Catid=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z|A-Z|0-9]{2,})$ index\.php\?cityname=$1 [L]

4. Consider enabling city secondary domain name access
If secondary domain name access is enabled, the prefix of the default secondary domain name is the city directory name
The city ID can be obtained according to the prefix of the secondary domain name. The functions are as follows:

function httpProtocolHead(){
    $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
    return $http_type;
}
function getSubDomain($url = ""){
    if(empty($url)){
        $http_type = httpProtocolHead();
        $url=$http_type.$_SERVER ['HTTP_HOST'];
    }else{
        if(stripos($url,'http://')===0){
            $http_type = 'http://';
        }else{
            $http_type = 'https://';
        }
    }

    preg_match("#".$http_type."(.*?)\.#i",$url,$match);
    return $match[1];
}
$curSub = getSubDomain();
$cityAll = get_allcities();
$cityDirectory = [];
foreach ($cityAll as $kk=>$vv){
    $cityDirectory[] = $vv['directory'];
}
if(in_array($curSub,$cityDirectory)){
    $subDomainOn = 1;
    $sql = "SELECT `cityid` FROM `{$db_mymps}city` WHERE `directory` ='{$curSub}' ORDER BY `cityid` ASC";
    $cityidBySubDomain = intval($db->getOne($sql));
}else{
    $subDomainOn = 0;
}

5.category.php file add function

if ($Catid && $rewrite == 'rewrite_py') {
    $detail = explode('/', $Catid);
    $detailCn = count($detail);

    if($subDomainOn==1){
        $cityid = $cityidBySubDomain;
    }else {
        if ($detailCn >= 2) {
            $cityname = $detail[0];
            $sql      = "SELECT `cityid` FROM `{$db_mymps}city` WHERE `directory` ='{$cityname}' ORDER BY `cityid` ASC";
            $cityid   = intval($db->getOne($sql));
        }
    }
    $dir_typename = end($detail);
    $otherVar = "";
    if(stristr($dir_typename,'-')!==false){
        $otherVar = $dir_typename;
        $dir_typename = $detail[$detailCn-2];
    }

    reset($detail);
    $cat_dir = array_flip(get_category_dir());
    $catid = $cat_dir[$dir_typename];

    if (!empty($otherVar)) {
        $detailc = explode('-', $otherVar);
        for ($i = 0; $i < count($detailc); $i++) {
            $_GET[$detailc[$i]] = ${$detailc}[$i] = str_replace(array('#@#', '#!#'), array('-', '/'), $detailc[++$i]);
        }
        extract($_GET);
    }
    $cat_dir = $Catid = $detail = $detailc = NULL;
}

After modification, the relevant pages of the classification can be accessed normally. Substation directory

Other functional modules have to be modified in this way. After all modifications are completed, the PC can access normally without generating a city directory. The mobile terminal operates similarly.

Keywords: PHP

Added by mccormr7 on Sun, 23 Jan 2022 20:12:31 +0200