views:

152

answers:

2

I would like to serve a different content from a single URL depending on whether the user is a browser or a RSS reader (hence avoiding an example.com/feed URL). Thus www.example.com/posts will return an (X)HTML page to a browser and an RSS feed to a feed reader.

What the architecturally most appropriate way of accomplishing this?

PS How is that for a soft-ball question... :)

+2  A: 

Let me introduce you to the User-Agent HTTP header. It will contain an identifying string for the client accessing your page. It can be faked but you just can't be 100% sure if it's a RSS reader or a browser.

Additionally, RSS readers might send Accept headers for rss content-types, which you may use to implement content negotiation (MultiViews in Apache).

But as there is no sure fire way, you better fail on the side of serving HTML more often than RSS, or better yet, do as everybody else does and provide a different feed for RSS.

Vinko Vrsalovic
+5  A: 

I'm not sure it's possible in all situations. Consider a user who uses Safari's RSS reader, assuming it uses the same browser identifier string when downloading an RSS feed, how would you tell the two modes apart?

I'd really re-consider this approach, there's nothing wrong with a separate feed URL.

Marc Charbonneau