Forum Moderators: phranque
Seems like a easy question but I am not nearly an expert in Apache/mod_rewrite so looking for help. I am trying to redirect URL substring from one host to another w/o recognition of the queries. For example,all calls with /irj/* should go to http://example.com/sso/?sourceURL=* . where "*" can be anything (has queries or has "?" sign (just sign, not a query parameter indicator)). I don't need to modify it anyhow or do any query transformation (as I will use the value of "sourceURL" after doing some logic inside "sso" application).
I managed to create the following .htaccess :
RewriteEngine on
RewriteRule ^irj/(.*)$ http://example.com/SSO/?sourceURL=$1 [NE,QSA]
It works fine although it tries to replace first "?" sign (regardless if it's a query indicator or just a character in the substring comes after /irj ) with "&". I tried w/o QSA but then I've got query parameters/values removed in the target substring.
Please help me to redirect the whole substring w/o making any changes to the target URL.
Thanks and regards,
Mike
[edited by: jdMorgan at 2:37 am (utc) on Nov. 22, 2008]
[edit reason] example.com [/edit]
RewriteEngine on
RewriteCond \%3f%{QUERY_STRING} (.+)
RewriteRule ^irj/(.*)$ http://example.com/SSO/?sourceURL=$1%1 [R=302,L]
Alternate method:
RewriteEngine on
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^irj/(.*)$ http://example.com/SSO/?sourceURL=$1\%3f%1 [NE,R=302,L]
If either or both of these methods work, the result will be that an encoded "?" will be used to begin the original query string when it is 'copied' into the new URL. This will happen whether or not there was a query string on the original URL. If that's not acceptable, let me know after you test the rules above -- These examples are just a 'proof of concept' at this point.
If you want to 'watch' the redirect happen and check the 'outgoing' URL, the Live HTTP Headers add-on for Firefox/Mozilla browsers is very handy for testing/debugging redirects.
Jim