简体   繁体   中英

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. The XML document is dynamically generated (I'm using ExpressionEngine).

The third party have requested that it must have a .xml extension to be read.

Any ideas how I could set up a .htaccess rule to only use a .xml file extension for this particular uri?

Most tutorials are concerned with removing file extensions adding file extensions to all urls, which doesn't help a .htaccess noob.

Many thanks in advance.

So if the URL the third party is using is: www.mydomain.com/feed/my_feed.xml

You want to add this in the htaccess file in your document root:

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. Frequently when I need to do this I'll just use the Pages module and put /something/something.xml as the Pages URI. Then you can point the page at any template you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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