Feed-Rewriting based on User-Agent (2 posts)

  1. pressing_questions
    Posted 10 years ago #

    I'd like to forward different feedreaders to different feed URLs

    1. I don't know where to put my custom mod_rewrite code in .htaccess without breaking the automatic permalink-functions in wp

    2. I also don't exactly know how to say:
    If it's user-agent 'A', go to URL a, else, go to URL b

    Any help is greatly appreciated!

  2. IsaacSchlueter
    Posted 10 years ago #

    Try this. Firefox will get the atom feed, and MSIE will get RSS2. Put it *before* the WordPress block:

    #sniff the user agent
    RewriteCond %{HTTP_USER_AGENT} firefox [NC]
    #make sure that they're not already requesting the right thing.
    RewriteCond %{REQUEST_FILENAME} !/feed/atom [NC]
    #Rewrite it and start over to interpret the new URI.
    RewriteRule ^(.*)/feed(/.*)?$ $1/feed/atom/ [N]
    #sniff the UA string
    RewriteCond %{HTTP_USER_AGENT} msie [NC]
    #check that they're not already looking for the right thing.
    RewriteCond %{REQUEST_FILENAME} !/feed/rss2 [NC]
    #rewrite and start over.
    RewriteRule ^(.*)/feed(/.*)?$ $1/feed/rss2/ [N]

    Note that this won't work prior to Apache version 2, due to the greedy regex in the RewriteRule. However, since "feed" can be appended to so many different URIs, it'd be really tricky to solve the problem with mod_rewrite in an Apache 1.3 compatible way, and depend a lot on the specifics of your site setup.

Topic Closed

This topic has been closed to new replies.

About this Topic