Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have


and I would like to rewrite it to this:


How can I do this?

I tried this:

RewriteCond %{REQUEST_URI} ^/cybersource/fp/clear.png/
RewriteCond %{QUERY_STRING}^(.*)org_id=1snn5n9w&session_id=sterling40272003&m=1(&.*)$ [NC]
RewriteRule^(.*)$ https://media.north.com/fp/clear.pngorg_id=1snn5n9w&session_id=sterling40272003&m=1 [R=301,L]

...but it's not working.

But here is the problem, I have multiple URLs for one host for example I have this:

If the request is

rewrite it to

If the request is

rewrite it to

share|improve this question
Presumably you mean external redirect, rather than an internal rewrite? What have you tried? – w3dk Jan 26 '14 at 21:25
I tried this out – raj Jan 26 '14 at 21:34
RewriteCond %{REQUEST_URI} ^/cybersource/fp/clear.png/ – raj Jan 26 '14 at 21:34
RewriteCond %{QUERY_STRING} ^(.*)org_id=1snn5n9w&session_id=sterling40272003&m=1(&.*)$ [NC] – raj Jan 26 '14 at 21:36
You can edit your question to include this additional information, rather than commenting. – w3dk Jan 26 '14 at 21:36

I think you're reasonably close. However, & (ampersands) are not HTML encoded in the request, so you should check just for & and not &. Special HTML characters should only be HTML encoded in your source HTML document.

I think the few omitted spaces (argument delimiters) are perhaps just due to the copy/paste of your code?

Try this (in .htaccess - I assume):

RewriteCond %{QUERY_STRING} ^.*org_id=1snn5n9w&session_id=sterling40272003&m=1(&.*)?$ [NC]
RewriteRule ^cybersource/fp/clear.png$ https://media.north.com/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=1 [R=301,L]

It looks a bit strange that you would be matching against the session_id, since the session id is usually something which changes often and is potentially a bit random - but I assume that is required?

This also checks for optional characters before and after your source query string, as hinted at by your code, although this isn't specifically stated in your original question.

If royatlon.north.com and media.north.com are served from the same place then you may need to also include a RewriteCond directive for the HTTP_HOST.

EDIT: In view of your recent edit, I think AgA's solution (mod_alias) is perhaps preferable, however, in keeping with mod_rewrite and assuming you do need to match the exact query string and not simply pass it through, then...

RewriteCond %{QUERY_STRING} ^org_id=1snn5n9w&session_id=sterling40272003&m=\d$ [NC]
RewriteRule ^cybersource/fp/clear.png$ https://media.north.com/fp/clear.png [R=301,L]

This matches a single digit (\d) at the end of the query string and the same query string is then passed through to the target.

share|improve this answer

Pl. try this:

RedirectMatch 301 ^/royatlon.north.com/cybersource/(.*) https://media.north.com/$1
share|improve this answer
did not work out, i don't know where am i making mistake at – raj Jan 27 '14 at 14:45
It should be RedirectMatch. I think this is perhaps the better solution, providing you don't need any more fine grained control on the pattern match. (+1) – w3dk Jan 27 '14 at 15:10
@raj I've corrected it as per w3d's advice. – AgA Jan 28 '14 at 5:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.