Jump to content

Converting two get variables in to clean URLs


alex3

Recommended Posts

Hi,

 

It seems I'm trying to do the opposite of what most people want to do with mod_rewrite, and as such I can't find a thing on it. I'm running a CodeIgniter site, with this .htaccess already implemented and working fine:

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

 

The problem is that sometimes I get URLs like these two, when dealing with PayPal:

http://sub.domain.com/controller/method/?token=value1
http://sub.domain.com/controler/method/?token=value1&PayerId=value2

What I'm after is to convert these URLs in to this form

http://sub.domain.com/controller/method/value1
http://sub.domain.com/controller/method/value1/value2

(I either get one two GET variables, one when the method is 'cancel', and two when the method is 'review'.)

 

So, obviously my current rule takes what ever is after the .com/ and gives it to index.php, which then processes it, this seems to be the most common .htaccess usage. I want to do the reverse of this (capture the GET variables). This seems to require a RewriteCond (because RewriteRule ignores GET variables, so you can't capture them using it), in addition to a RewriteRule, but I don't know how to pass the GET variables I capture in to the new URL.

 

This seems overly complex, even pointers in the right direction would be immensely appreciated, this is driving me insane!

 

Cheers,

Alex

Link to comment
Share on other sites

I managed to fiddle about and got a similar result to what you got, works perfectly, very pleased indeed with it. Thanks enormously for your help :) Here's my finished .htaccess, for prosperity:

 

<IfModule mod_rewrite.c>
RewriteEngine On
# Change this for your own path
RewriteBase /
# This is for when user is reviewing order
RewriteCond %{QUERY_STRING} ^token=(.*)&PayerID=(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/%1/%2? [L]
# This is for when the user cancels the order from the PayPal interface
RewriteCond %{QUERY_STRING} ^token=(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/%1? [L]
# This one is for all others
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/%1/%2? [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

 

And then with CodeIgniter grabbing the values is just as you would normally, method($token, $paypal_id).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.