2014-02-09 41 views
0

我想創建一個動態sitemap.xml文件使用php和.htaccess從我的數據庫。我sitemap.php文件:.htaccess重寫網站地圖php到xml

<? 
include "db.php"; 
header("Content-Type: text/xml;charset=iso-8859-1"); 
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> 
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"> 
"; 

{ 
while($row = mysql_fetch_array($result)) { 
    $url = $row["url_code"]; 
echo " <url> 
     <loc>http://domain.com/$url</loc> 
    </url> 
"; 
} 
} 
?> 
</urlset> 

我有以下.htaccess文件:

RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^stats [NC] 
RewriteRule^- [L] 
RewriteCond %{HTTP_HOST} !^domain.com$ [NC] 
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] 
Rewriterule ^sitemap.xml$ sitemap.php [L] 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule . index.php [L] 

但我得到的是未找到404錯誤。我試過了:

RewriteEngine On 
Rewriterule ^sitemap.xml$ sitemap.php [L] 

但是得到同樣的錯誤。我哪裏錯了?

回答

0

一切似乎現在工作,沒有改變任何東西! 因此這是你如何做到這一點

-1

試試這個:

RewriteRule ^sitemap\.xml$ xmlsitemap.php [L] 
RewriteRule ^sitemap$ sitemap.php [L]