codebyren Posted December 24, 2009 Share Posted December 24, 2009 Hi everyone, I am trying to rewrite a url like: https://mysite.com/payments/update/id/?result=encryptedStringHere&userid=myUsername to: https://mysite.com/index.php?url=/payments/update/id/result:encryptedStringHere/userid:myUsername The ?result=encryptedStringHere&userid=myUsername in the orignal URL is appended by a payment gateway I am using to process payments so is really outside of my control. Other than this, the URLs for my site work fine using my current .htaccess setup: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # RewriteRule for hits from Payment Gateway # the commented out rule below doesn't work... need help # RewriteRule ^/payments/update/([0-9]+)/?result=(.*)&userid=(.*)$ index.php?url=/payments/update/$1/result:$2/userid:$3 [PT,L] # I'm assuming if the URL doesn't match rule above (when uncommented), this next one will be used: RewriteRule ^(.*)$ index.php?url=$1 [PT,L] </IfModule> The above basically involves Anything in the URL after the domain being appended as parameters to index.php, so http://www.site.com/controller/action is rewritten to http://www.site.com/index.php?url=/controller/action This seems to break with the parameters appended by the payment gateway though (due to the additional "?" and "&" I guess). Would appreciate any help or suggestions from someone with more regex or mod_rewrite experience... Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/186291-mod_rewrite/ Share on other sites More sharing options...
rajivgonsalves Posted December 24, 2009 Share Posted December 24, 2009 the rewrite is on the REQUEST_URI and not on the query string you'll have to do something like this <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # RewriteRule for hits from Payment Gateway # the commented out rule below doesn't work... need help RewriteRule ^payments/update/([0-9]+)/$ index.php?update=$1&vars=%{QUERY_STRING} [L] # I'm assuming if the URL doesn't match rule above (when uncommented), this next one will be used: #RewriteRule ^(.*)$ index.php?url=$1 [PT,L] </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/186291-mod_rewrite/#findComment-983832 Share on other sites More sharing options...
codebyren Posted December 25, 2009 Author Share Posted December 25, 2009 Thanks for the help Rajiv. Useful to know that the RewriteRule does not apply to the query string - took a fair bit more reading to fully understand this though. I eventually achieved what I was looking for by using: RewriteCond %{QUERY_STRING} ^result=(.*)&userid=(.*)$ before: RewriteRule ^payments/update/([0-9]*)/?.*$ index.php?url=payments/update/$1/result:%1/userid:%2 [L] Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/186291-mod_rewrite/#findComment-983926 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.