RewriteRule with Query_String

RewriteRule with Query_String - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the RewriteRule with Query_String error on your web browser. Problem :


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


Solution :

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.



Pl. try this:



RedirectMatch 301 ^/royatlon.north.com/cybersource/(.*) https://media.north.com/$1

We hope that this article has helped you resolve the redirects, query-string, error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=