Jump to content

mod_rewrite


codebyren

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/186291-mod_rewrite/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/186291-mod_rewrite/#findComment-983832
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/186291-mod_rewrite/#findComment-983926
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.