Take the 2-minute tour ×

Is it possible to redirect url parameters as segments in .htaccess file?




share|improve this question
add comment

closed as off topic by casperOne Jul 27 '12 at 13:28


1 Answer

up vote 2 down vote accepted

Yes. Try this:

RewriteCond %{QUERY_STRING} parameter=(.*)
RewriteRule test/index\.php test/%1

According to "What is matched?" in the mod_rewrite docs, the query string (part after the ?) is separated out into the QUERY_STRING variable, which then has to be tested separately from the main part of the URL. In RewriteCond, the parameter value is captured by the regular expression within the parentheses (.*), and is then available as %1 in the RewriteRule.

share|improve this answer
doesn't redirect if I have the \?parameter=(.*) part –  williamcarswell Nov 2 '11 at 14:42
Sorry - corrected. –  Andrew Schulman Nov 2 '11 at 14:44
Thanks, can you explain to everyone how the RewriteCond works –  williamcarswell Nov 2 '11 at 14:49
add comment
