mod_rewrite: redirect specific get query

Using .htaccess and mod_rewrite I want to redirect this:
http://example.com/index.php?option=com_sitemap&view=xml 

To this:
http://example.com/sitemap.xml [L,R=301]

My code below does NOT work:
RewriteRule ^index.php?option=com_sitemap&view=xml http://example.com/sitemap.xml [L,R=301]

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
 
David S.Connect With a Mentor Commented:
RewriteRule doesn't look at the query string. To do that you need to use a RewriteCond with it.

RewriteCond %{QUERY_STRING} option=com_sitemap&view=xml
RewriteRule ^\/?index.php http://example.com/sitemap.xml [L,R=301]

Open in new window

0
 
farzanjCommented:
Try
RewriteRule "^/index.php.*" site.xml [L,R=301]
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.