1

I'm working on a PHP application using CodeIgniter. The application will be accessible for people who are accessing it through a proxy that will add some information to the querystring. So if a user request the following : http://myapplication.com/main/, the proxy will automatically transform that in http://myapplication.com/main/?user=userid.

Please don't criticize me on that way to pass the user id, it's the client's request to do it like that, not mine! ;)

I'm not very experienced with CodeIgniter, but I know enough to know that it uses segments instead of querystring but I can change it to querystring. The thing is, I don't want to use querystring everywhere.

The thing is, I'm not working through that proxy, so I want to simulate that on my local computer. If I enter manually in the location bar : http://localhost/main/?user=12345, I can get it and use it in my application using $_GET['user']. But I want the user id on all requests, without having to add it manually. So here's what I did in my .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|_|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1?user=12345 [L]

My .htaccess is working fine because if I print_r($_GET) in my index.php file, the information is there. But if I try the same from my CI controller, the $_GET array is empty. The weird thing is, as I said above, if I type it manually in the browser's location bar, the information is available from my controller.

Can anyone help me figure out what causes my querystring added in .htaccess to be unavailable in my CI controllers?

Thanks!

Gabriel
  • 2,720
  • 4
  • 28
  • 36
  • I don't know if I understood, but you can enable URLs like this in CI. Please, see the following link: http://codeigniter.com/user_guide/general/urls.html ('Enable Query Strings' section) – Fran Verona Mar 14 '11 at 20:38
  • @Fran Verona: I am aware of that possibility, but if I activate querystrings like that, my main url will be localhost/index.php?c=main and I don't want that. I want to keep the url using segments like localhost/main/ – Gabriel Mar 14 '11 at 20:53
  • Ok. Maybe bensiu's answer could be the answer then ;) – Fran Verona Mar 14 '11 at 20:55

1 Answers1

1
RewriteRule ^(.*)$ /index.php/?user=12345&$1 [L]

Edit: how you check it ? by "the $_GET array is empty" if yes I suggest to read Enabling $_GET in codeigniter

Community
  • 1
  • 1
bensiu
  • 24,660
  • 56
  • 77
  • 117
  • I'm not sur if I understand the logic of this... it would put the querystring before the segments? I tried and it doesn't work... :( – Gabriel Mar 14 '11 at 20:54
  • The Rewrite part doesn't change a thing, but the link to which you directed me did the trick! Thanks! – Gabriel Mar 14 '11 at 21:55