für kleine Webprojekte welche nur aus statischen HTML Dateien bestehen, hier mal ein kleiner Schnipsel zur Generierung einer sitemap.xml
als sitemap.xml speichern
als sitemap.xml speichern
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?
/**
* Generierung der sitemap.xml aus dem aktuellen
* Dateisystem, mit letztem Änderungsdatum
**/
$domain = $_SERVER['SERVER_NAME'];
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
."<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\""
." xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
."xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 "
."http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\r\n";
$path = dirname( __FILE__ ).'/';
$handle = opendir( $path );
while( $file = readdir( $handle ) ) {
if( is_file( $path.'/'.$file ) && trim( $file, '.' ) ) {
if( substr( $file, -5 ) == '.html' ) {
$time = filectime( $path.$file );für die ungekürzte Fassung bitte einloggen
und eine .htaccess mit folgendem Inhalt anlegen
Code
1
2
3
4
2
3
4
# Rewrite für die sitemap.xml
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap\.xml$ sitemap.php