Mobile app version of vmapp.org
Login or Join
Lengel546

: RewriteRule with Query_String 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=1sn

@Lengel546

Posted in: #QueryString #Redirects

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:
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^(.*)$ 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 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 media.north.com/fp/clear.png?org_id=1snn5n9w&session_id=sterling40272003&m=2

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Lengel546

2 Comments

Sorted by latest first Latest Oldest Best

 

@Steve110

Pl. try this:

RedirectMatch 301 ^/royatlon.north.com/cybersource/(.*) media.north.com/

10% popularity Vote Up Vote Down


 

@Ogunnowo487

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$ 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$ 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme