CodeIgniter Forums
How To use Query Strings with CodeIgnter (and still have Pretty URLs) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How To use Query Strings with CodeIgnter (and still have Pretty URLs) (/showthread.php?tid=26820)



How To use Query Strings with CodeIgnter (and still have Pretty URLs) - El Forum - 01-24-2010

[eluser]NTICompass[/eluser]
I have query strings enabled, and I still use pretty URLs in CodeIgniter.

Using .htaccess, I can rewrite the URLs correctly and also pass query strings to the controllers.

The following code is used for my RPX Login library (http://codeigniter.com/wiki/RPX_Login/).

Code:
RewriteEngine On
Options +FollowSymlinks
Options -Indexes
RewriteBase /

RewriteRule ^rpxlogin$ index.php?c=rpx [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Basically http://example.com/rpxlogin calls the controller named rpx. When http://example.com/rpxlogin?test=123 is called it is rewritten as http://example.com/index.php?c=rpx&test=123

Hope this helps people.