Forum Moderators: phranque
# RSS Redirects
RewriteRule ^index\.php\?id\=5$ /?q=latest-news/feed
RewriteRule ^Business_Aviation.xml$ /?q=taxonomy/term/9/feed
RewriteRule ^Air_Transport_and_cargo.xml$ /?q=taxonomy/term/6/feed
RewriteRule ^Defense.xml$ /?q=taxonomy/term/13/feed
RewriteRule ^Accidents_Safety_Security_and_Training.xml$ /?q=taxonomy/term/1/feed
RewriteRule ^Airports_Heliports_and_FBOs.xml$ /?q=taxonomy/term/7/feed
RewriteRule ^Avionics_and_ATC.xml$ /?q=taxonomy/term/8/feed
RewriteRule ^Cabin_Interior_and_Electronic.xml$ /?q=taxonomy/term/11/feed
RewriteRule ^Charter_and_Fractional.xml$ /?q=taxonomy/term/12/feed
RewriteRule ^Financing_Insurance_and_Taxes.xml$ /?q=taxonomy/term/14/feed
RewriteRule ^General_Aviation.xml$ /?q=taxonomy/term/15/feed
RewriteRule ^Maintenance_and_Modifications.xml$ /?q=taxonomy/term/16/feed
RewriteRule ^People.xml$ /?q=taxonomy/term/17/feed
RewriteRule ^Regulations_and_Government.xml$ /?q=taxonomy/term/19/feed
RewriteRule ^Rotorcraft.xml$ /?q=taxonomy/term/21/feed
RewriteRule ^index\.php\?id=5$ /?q=latest-news/feed [L] RewriteRule ^Business_Aviation.xml$ /?q=taxonomy/term/9/feed [L] example.com/Business_Aviation.xml then the server will look for content in /index.php?q=taxonomy/term/9/feed To be clear what you want, the above rule says that if something asks for example.com/Business_Aviation.xml then the server will look for content in /index.php?q=taxonomy/term/9/feed
RewriteCond %{QUERY_STRING}
RewriteRule ^index\.php\?id=5$ /?q=latest-news/feed [L]
There is at least one problem there, the biggie being unescaped slashes are not a valid or allowed character in a query string according to the HTTP specs.
Is that right? So {QUERY_STRING} just directs Apache to include the query string in the match?
Query Strings
The Query String, also known as a Parameter, is the part of an url after the question mark. Question = query.
By default, rewrites simply ignore the query string. That is, mod_rewrite stashes the query in a safe place, does its stuff to the part before the question mark, and then reappends the original query.
Changing a Query
#1 To delete a query, add a ? to the end of your rewrite target.
#2 To replace a query—or create a new one—add ?blahblah to the rewrite target. The blahblah can be either literal text, or stuff you captured earlier. (#1 and #2 are really the same thing: you're just replacing the query with either something or nothing.)
#3 To add to an existing query, again put ?blahblah at the end of the target, but also add [QSA] to your flags (the bracketed items at the end of the Rule). It stands for "Query String Append", meaning that the blahblah is to be added to the existing query—if any—instead of replacing it.
Getting the Query
You only need to retrieve the original query if
#1 you want the rewrite to behave differently depending on what the query was
or
#2 you need to change or delete the query
Add a Condition that says
RewriteCond %{QUERY_STRING} blahblah
using your ordinary Regular Expressions, anchors and ! as needed.
To test whether there was a query at all
RewriteCond %{QUERY_STRING} .
which simply means "If the query contains at least one character of any kind".
If you need to capture any of the query, use parentheses as usual. In the rewrite target, the captures will be %1, %2 etc instead of $1, $2 etc, because they are coming from a Condition instead of the Rule. Each set is separately numbered, so the first capture from the Rule will still be $1.
Is that right? So {QUERY_STRING} just directs Apache to include the query string in the match?No. The pattern in the RewriteRule must contain only the path part of the URL. RewriteRule itself cannot "see" or match the protocol, domain, port number or query string. You have to put the pattern for the query string part of the request in a RewriteCond directly above the particular RewriteRule that it will apply to.