简体   繁体   English

从XML网站地图生成器中删除php扩展名

[英]Removing php extension from XML sitemap generator

My developer is out for holidays and I'm trying to figure out how to remove php extension from my XML sitemap generator. 我的开发人员正在休假,我正在尝试弄清楚如何从XML网站地图生成器中删除php扩展名。

Here's the code that's needs to be changed: 这是需要更改的代码:

    //remaining main pages:
$pages=array();
$query="SELECT DISTINCT strona FROM `sites_table`";
if($result=$GLOBALS['mysql']->query($query))
{
    $i=0;
    while($row=$result->fetch_assoc())
    {
        if($row['site']!="/index.php")
        {
            $pageName=substr($row['site'],1);
            array_push($pages,$pageName);
            write(insertIntoTemplate($pageName,"0.8","hourly"));
        }
    }
    $result->free();
}
else 
    echo $dbErrorMsg;

The MySQL query just prints the array of sites like: news.php, sports.php, politics.php etc. MySQL查询仅显示一系列网站,例如:news.php,sports.php,policy.php等。

All I need is just remove this .php extension ;) I've did that already with special .htaccess file but now I need to just inform Google that I'm using non .php sites. 我只需要删除此.php扩展名即可;)我已经使用特殊的.htaccess文件进行了此操作,但现在我需要通知Google我正在使用非.php网站。

Looks like you should be able to change the line: 看起来您应该能够更改行:

$pageName=substr($row['site'],1);

to: 至:

$pageName=substr($row['site'],1, -4);

Note: All this code does is remove the last four characters - this may break other sections of the site if there are places where the extension is expected, items that don't follow the .php model, etc. 注意:这些代码所做的只是删除最后四个字符-如果存在需要扩展名的地方,不遵循.php模型的项目等,则这可能会破坏网站的其他部分。

This should work for you, so long as you are ok with replacing all occurrences of .php with an empty string. 只要您可以将所有出现的.php替换为空字符串,这对您就可以使用。 This does not take into account any edge cases that may exist in your application, and you'd need to speak with your developer to know this for sure if you are unsure yourself. 这没有考虑到应用程序中可能存在的任何极端情况,因此如果您不确定自己是否需要,则需要与开发人员交谈以确保知道这一点。

//remaining main pages:
$pages=array();
$query="SELECT DISTINCT strona FROM `sites_table`";
if($result=$GLOBALS['mysql']->query($query))
{
    $i=0;
    while($row=$result->fetch_assoc())
    {
        if($row['site']!="/index.php")
        {
            //do a string replace of all occurrences of .php 
            $pageName=substr(str_replace('.php','',$row['site']),1);
            array_push($pages,$pageName);
            write(insertIntoTemplate($pageName,"0.8","hourly"));
        }
    }
    $result->free();
}
else 
    echo $dbErrorMsg;

It seems that $pageName was also uses for some other pages, so I just did it this way and no errors now: 看来$ pageName也用于其他一些页面,所以我只是这样做,现在没有错误:

            //do a string replace of all occurrences of .php 
            $pageName=substr($row['site'],1);
            array_push($pages,$pageName);
            $pageName2=substr(str_replace('.php','',$row['site']),1);
            array_push($pages,$pageName);
            write(insertIntoTemplate($pageName2,"0.8","hourly"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM