I’m having a hell of a time getting this to cooperate. Basically I’m trying to redirect my site’s feeds to Feedburner, but I don’t want any feed URLs with parameters on them to redirect.
For example:
mysite.com/feed/ should redirect to http://feeds.feedburner.com/mysite
But this URL should not redirect:
mysite.com/feed/?post_type=custom
Right now that second URL is getting redirected to http://feeds.feedburner.com/mysite?post_type=custom and that’s problematic. I want that URL to remain untouched. Any URL that has a ? after the /feed/ should be left alone.
Here’s my code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/mysite [R=302,NC,L]
</IfModule>
I played around with the RewriteRule but I couldn’t get it to cooperate. I tried doing a Negative Lookahead for a question mark, but it didn’t alter anything.
The reason ([_0-9a-z-]+)? is used is because WordPress creates like 5 different feeds.
Thanks in advance for any help. I feel like a dummy since I was heavy into regex a couple months ago and now I can’t do it.
The question mark in a URL is not matched against in the RewriteRule, as this matches against the REQUEST_URI, not the QUERY_STRING. If you wish to not redirect if there is a query string you should be able to just add in a RewriteCond %{QUERY_STRING} ^$
Then it will only redirect if the query string is empty.