以下代码是针对SITEMAP的,我用PHP编写了它,并通过文件".htaccess">将其转换为XML。
.htaccess
## Sitemap.php To Sitemap.xml
RewriteRule ^sitemap.xml$ sitemap.php [L]
网站地图.php
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
<HEADLINE><BYLINE>XML Sitemap Index : </BYLINE></HEADLINE>
<url>
<loc><a href="http://www.sample.com">http://www.sample.com</a></loc>
<changefreq>Always</changefreq>
<priority>1.0</priority>
<lastmod></lastmod>
</url>
</urlset>
另请参阅:http://s6.picofile.com/file/8380482426/link_sitemap.jpg
在此处输入图像描述
例如,请参阅Yoast,In Table站点地图单击链接。 当我单击链接时,它会打开页面。
我想单击下面的代码并将该链接作为页面打开。
<loc><a href="http://www.sample.com">http://www.sample.com</a></loc>
代码有什么问题?
您网站的普通XML站点地图应如下所示:
<urlset xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>your URL1</loc>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>your URL2</loc>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
...
</urlset>
或者只是在 https://www.xml-sitemaps.com/为您的网络生成一个
或者创建一个PHP脚本,该脚本将直接输出具有相同结构的XML文件。那么就不需要使用 htaccess。只需在 php 中使用这样的标头:
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8" ?>';