简体   繁体   English

如何使用.htaccess将.xml扩展名添加到特定URI

[英]How to add a .xml extension to a specific URI using .htaccess

I have a URL at the moment www.mydomain.com/feed/my_feed/ which writes out an xml document to be read by a third party. 我现在有一个网址www.mydomain.com/feed/my_feed/,它写出一个XML文档供第三方阅读。 The XML document is dynamically generated (I'm using ExpressionEngine). XML文档是动态生成的(我正在使用ExpressionEngine)。

The third party have requested that it must have a .xml extension to be read. 第三方已请求必须具有.xml扩展名才能读取。

Any ideas how I could set up a .htaccess rule to only use a .xml file extension for this particular uri? 有什么想法可以设置.htaccess规则以仅对此特定uri使用.xml文件扩展名吗?

Most tutorials are concerned with removing file extensions adding file extensions to all urls, which doesn't help a .htaccess noob. 大多数教程都关注删除文件扩展名,将文件扩展名添加到所有url,这对.htaccess noob没有帮助。

Many thanks in advance. 提前谢谢了。

So if the URL the third party is using is: www.mydomain.com/feed/my_feed.xml 因此,如果第三方使用的URL是: www.mydomain.com/feed/my_feed.xml

You want to add this in the htaccess file in your document root: 您要将其添加到文档根目录的htaccess文件中:

RewriteEngine On
RewriteRule ^/?feed/my_feed.xml$ /feed/my_feed/ [L]

I've had trouble using .htaccess to rewrite the .xml off of a URL before. 我以前无法使用.htaccess重写URL的.xml。 Frequently when I need to do this I'll just use the Pages module and put /something/something.xml as the Pages URI. 通常,当我需要执行此操作时,我只会使用Pages模块并将/something/something.xml用作Pages URI。 Then you can point the page at any template you want. 然后,您可以将页面指向所需的任何模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM