.htaccess 如何将请求重定向到扩展名为.xml的文件

.htaccess 如何将请求重定向到扩展名为.xml的文件,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,在我的网站上,我想阻止对xml文件的访问 例如,当请求以下文件时 http://example.com/a_File.xml 或 我希望浏览器重定向到其他页面http://example.com/different_Page.html 以下是我目前在.htaccess中的内容: SetEnvIf Request_uri "\.xml$" blocked RewriteEngine ON RewriteCond %{ENV:blocked} ^blocked RewriteRule (.*

在我的网站上,我想阻止对xml文件的访问

例如,当请求以下文件时

http://example.com/a_File.xml 

我希望浏览器重定向到其他页面
http://example.com/different_Page.html

以下是我目前在
.htaccess
中的内容:

SetEnvIf Request_uri "\.xml$" blocked

RewriteEngine ON
RewriteCond %{ENV:blocked} ^blocked 
RewriteRule (.*) 404.php [R=301]
它并没有阻止它,我仍然可以查看我的xml文件

用于以case-instive方式匹配请求URI字符串:

RewriteEngine on
RewriteRule \.xml$ /different_Page.html [NC,R=301,L]
SetEnvIfNoCase Request_uri "\.xml$" blocked

RewriteEngine ON
RewriteCond %{ENV:blocked} 1 
RewriteRule ^(.*)$ 404.php [NC,L,R=301]

奇怪,它还是不起作用。我仍然可以转到我的xml files.TicToc,你的服务器上是否启用了mod_重写?我的系统有问题,现在可以工作了。谢谢
SetEnvIfNoCase Request_uri "\.xml$" blocked

RewriteEngine ON
RewriteCond %{ENV:blocked} 1 
RewriteRule ^(.*)$ 404.php [NC,L,R=301]
RewriteEngine ON
RewriteCond %{REQUEST_URI} \.xml$
RewriteRule (.*) 404.php [R=301]