Welcome Guest, Not a member yet? Register   Sign In
.htaccess - convert querystring variables into url segments?
#1

[eluser]Matthew Pennell[/eluser]
I'm having an .htaccess problem, hopefully someone can help me out. Smile

I'm working on something that uses a third-party remote API which it accesses via cURL, but the API only uses querystrings to return the authorization key to my app. So I can set the callback URL, but it will always send back the response as:

http://localhost/myapp/controller/method...d1e1f1f1e1

Obviously this isn't much use to CodeIgniter, so I thought I could use .htaccess to intercept those requests and rewrite the url to make the token into a url segment:

http://localhost/myapp/controller/method...d1e1f1f1e1

Here's my .htaccess:

Code:
RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)\?auth_token=(.*)$ /index.php/$1$2 [L]
RewriteRule ^(.*)$ /index.php/$1 [L]

Unfortunately, this setup gives me a 500 Internal Server Error. Sad

Anyone know how to do this properly?
#2

[eluser]Josepzin[/eluser]
How do you solve?
#3

[eluser]Matthew Pennell[/eluser]
I gave up in the end. Wink

Basically I just redirected the auth_token matching URLs to another page (outside of CI) that did a simple header() redirect to the relevant controller/method with the auth_token appended as url_segment(3).

Code:
RewriteCond %{QUERY_STRING} ^auth_token=(.*)$
RewriteRule ^purchase/success/$    /redirect_auth_token.php?result=success&auth;_token=%1 [L,R=301]
#4

[eluser]Josepzin[/eluser]
Thanks!
#5

[eluser]huzzi[/eluser]
I'm having this same problem, is it not possible to do it with htaccess? I tried the code below but it does not work.

Code:
RewriteCond %{REQUEST_URI}  ^payment\.html$
RewriteCond %{QUERY_STRING} ^oid=$
RewriteRule ^(.*)$/payment/index/%1 [QSA,L]

Any idea?
#6

[eluser]Eric Barnes[/eluser]
Editing these in config should work:
Code:
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
#7

[eluser]huzzi[/eluser]
I managed to get it to work with the mod_rewrite code below if anyone interested.

Code:
RewriteCond %{REQUEST_URI}  ^/payment\.html$
RewriteCond %{QUERY_STRING} &?oid=([^&]+)&?
RewriteRule ^payment.html$ payment/redirect$1/%1? [R=301,L]




Theme © iAndrew 2016 - Forum software by © MyBB