I have an RSS feed example.com/?format=feed&type=rss
from an old Joomla install. The site is now built with Jekyll, and uses a new URL example.com/rss.xml
for the RSS feed.
Rewrite rules aren't working for me since the URL starts with "?". I've got it working with an if directive but want to avoid using if.
Here's the working if directive which I want to replace with a rewrite or redirect:
if ($args ~ "type=rss") {
rewrite ^ https://example.com/rss.xml? permanent;
}
Can the if directive for the URL starting with "?" be replaced with a rewrite or redirect?
alexyten is right. In this case there is no other way to handle this as what you are trying to match is actually not part of the location but it is rather a GET argument. And, also, as alexeyten suggested, I would use
if ($arg_argname = "exact string")
. Regular expressions have both a performance overhead as well as if they are not correctly written they can lead to unexplained redirects and rewrites.For example, if you want to match the fact that the
format
parameter has the valuefeed
, you would need to do something like this:if ($arg_format = "feed")
.