Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess URL重写(sitemap.xml到sitemap.php)_.htaccess_Url_Mod Rewrite - Fatal编程技术网

.htaccess URL重写(sitemap.xml到sitemap.php)

.htaccess URL重写(sitemap.xml到sitemap.php),.htaccess,url,mod-rewrite,.htaccess,Url,Mod Rewrite,下面是我当前的.htaccess文件。我想添加另一个条件/规则,如果请求sitemap.xml,则会提供sitemap.php。请帮忙:) Options+FollowSymLinks 重新启动发动机 重写基/ 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D 重写规则^(.*)$index.php?文件名=$1[L,QSA] 您可以明确地执行以下操作: Options +FollowSymLinks <IfModule mo

下面是我当前的.htaccess文件。我想添加另一个条件/规则,如果请求sitemap.xml,则会提供sitemap.php。请帮忙:)

Options+FollowSymLinks
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?文件名=$1[L,QSA]

您可以明确地执行以下操作:

Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /

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

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
Options+FollowSymLinks
重新启动发动机
重写基/
重写规则^sitemap.xml$sitemap.php[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?文件名=$1[L,QSA]

不过,您可能会在执行此操作时遇到问题。。。您应该为爬行器创建排除,以便它们仍然接收sitemap.xml

重写规则^sitemap.xml$public/sitemap.php[L]

使用下面的代码确保您的php文件以xml形式加载

header('Content-Type: text/xml');

这不会将这些条件应用于xml行而不是初始重写吗?我对htaccess的回忆有点模糊,但我认为新规则必须在声明索引条件之前出台。抢手货我没有考虑到它会在
%{REQUEST\u FILENAME}之后停止-f
Ok,那么我应该在“RewriteCond%{REQUEST_FILENAME}!-f”之后尝试使用这个新规则吗?我有一个.php文件,可以动态生成站点地图,但希望爬虫程序能够找到并使用sitemap.xml查看其内容。Hrm。。。就个人而言,如果我使用动态站点地图生成器(由于各种原因我根本不使用站点地图),我会将其设计为在添加新内容时重新抓取网站并输出一个新的.xml文件,并使其与公共区域断开连接。那么关于蜘蛛的问题就没有意义了。
header('Content-Type: text/xml');