Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have

http//royatlon.north.com/cybersource/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=1

and I would like to rewrite it to this:

https://media.north.com/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=1

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

http//royatlon.north.com/cybersource/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=1
rewrite it to
https://media.north.com/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=1

If the request is

http//royatlon.north.com/cybersource/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=2
rewrite it to
https://media.north.com/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=2

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

2 Answers 2

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
add comment

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 at 14:45
2  
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) –  w3d Jan 27 at 15:10
    
@raj I've corrected it as per w3d's advice. –  AgA Jan 28 at 5:01
add comment

Your Answer

 
discard

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.