0%

case php站点地图生成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
require_once("Kiss.php");
$kiss=new Kiss("db1","/ss/");//数据库路径
$posts=$kiss->getPostsByTime(20000);
foreach($posts as $post)
echo "
<url>
<loc>https://steelsheetstock.com/ss/{$post["rowid"]}.html"."</loc>
</url>";
require_once("Kiss.php");
$kiss=new Kiss("db2","/ssp/");//数据库路径
$posts=$kiss->getPostsByTime(20000);
foreach($posts as $post)
echo "
<url>
<loc>https://steelsheetstock.com/ssp/{$post["rowid"]}.html"."</loc>
</url>";
echo "</urlset>";
?>

配合伪静态.htaccess使用

1
2
3
4
5
6
#Kiss for apache兼容用。无需任何修改。
RewriteEngine On
RewriteRule ^a\.xml$ a.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /list.php [L]

Nginx伪静态语法

1
2
3
4
5
6
7
8
9
10
11
rewrite ^/sitemap\.xml$ /sitemap.php  ##sitemap.php转sitemap.xml
rewrite ^/sitemap\.xml$ /sitemap.php;
if (!-f $request_filename){
set $rule_1 1$rule_1;
}
if (!-d $request_filename){
set $rule_1 2$rule_1;
}
if ($rule_1 = "21"){
rewrite /. /list.php last;
}