我有一个php文件,它动态生成站点地图:
<?php
$do = "2way";
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("database",$db);
$sql = "select * from url_urls WHERE private = 'n' AND short = '$do'";
$result = mysql_query($sql, $db) or die(mysql_error());
$date = date('c',time());
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)) {
$short = $row["url_code"];
echo " <url>
<loc>http://$do/$short</loc>
<changefreq>weekly</changefreq>
<lastmod>$date</lastmod>
</url>
";
}
}
?>
</urlset>
它应该与htaccess一起工作:
RewriteEngine On
RewriteBase /
Rewriterule ^sitemap.xml$ sitemap.php [L]
我需要在htaccess中添加以下行:
RewriteCond %{REQUEST_URI} !'.(css|js|ttf|eot|xml|svg|woff)$
RewriteRule ^(.*)$ index.php?url_code=$1 [L]
但当我把它们这样放在一起时:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !'.(css|js|ttf|eot|xml|svg|woff)$
RewriteRule ^(.*)$ index.php?url_code=$1 [L]
Rewriterule ^sitemap.xml$ sitemap.php [L]
php文件不再生成站点地图。显然htaccess是个问题,有人能帮忙吗?
更改规则顺序并将php
包括在排除列表中:
RewriteEngine On
RewriteBase /
Rewriterule ^sitemap'.xml$ sitemap.php [L]
RewriteCond %{REQUEST_URI} !'.(php|css|js|ttf|eot|xml|svg|woff)$
RewriteRule ^(.+)$ index.php?url_code=$1 [L]