alex3 Posted February 24, 2010 Share Posted February 24, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193243-converting-two-get-variables-in-to-clean-urls/ Share on other sites More sharing options...
cags Posted February 26, 2010 Share Posted February 26, 2010 RewriteCond %{QUERY_STRING} ^token=([a-zA-Z0-9]+)$ RewriteRule ^.*$ http://sub.domain.com/controller/method/%1 Quote Link to comment https://forums.phpfreaks.com/topic/193243-converting-two-get-variables-in-to-clean-urls/#findComment-1018429 Share on other sites More sharing options...
alex3 Posted February 27, 2010 Author Share Posted February 27, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/193243-converting-two-get-variables-in-to-clean-urls/#findComment-1019028 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.