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

时间:2015-07-18 03:01:12

标签: .htaccess mod-rewrite

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

例如,当请求以下文件时

http://example.com/a_File.xml 

http://example.com/some_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文件。

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

使用SetEnvIfNoCase Directive以不区分大小写的方式匹配Request_URI字符串:

SetEnvIfNoCase Request_uri "\.xml$" blocked

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

答案 2 :(得分:0)

RewriteEngine ON
RewriteCond %{REQUEST_URI} \.xml$
RewriteRule (.*) 404.php [R=301]