Search code examples
.htaccesssslhttpsopayo

SagePay fails when forcing https


I'm using the following in my .htaccess to force https on;

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]

However this seems to cause SagePay to throw a 5003 error and a 500 http error.

The site has a valid SSL and was just installed yesterday and if I comment out these lines it works correctly with SagePay. MY callback pages are linked as https so SagePay redirects back to my site with https on so it's not as if SagePay is looking at the address and sees that it's being changed.

I don't have to force https, it won't be the end of the world, but I want to do so for the obvious benefits of https. Am I doing anything wrong, is there something I can do to fix this problem and keep forcing https?


Solution

  • After contacting SagePay support directly and looking at their logs for an example transaction I was able to see that our callback url (that was sent along with the post request to SagePay before the user even got to the SagePay payment portal) was manually set to be http rather than https.

    This meant that when SagePay tried to post back to our website to see what to do next it was using an http url which would then have been redirected via our htaccess rules.

    I can only assume SagePay's security considered this as tampering or something like that and considered that the transaction was not safe.

    After manually changing our callback url to https, everything works as expected.