Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Codeigniter rewrites query strings like the following:

http://somedomain.com/index.php?q=something

to become:

http://somedomain.com/index.php/q/something

I'd like to imitate this behavior on a (very) lightweight website I am developing for a wedding RSVP system. I don't want the bloat of codeigniter, nor do I need anything else that it provides. The only thing I'd like is this.

Unfortunately, I don't know how to setup a mod-rewrite rule that accomplishes this. I can setup a rule that translates /q/something into ?q=something, but I can't get one that does that without changing the URL the user is viewing.

I'm basically looking for something that is, in effect, a "silent" version of the rewrite. That is, I want something that rewrites q/something to ?q=something, but leaves the user's URL in their address bar as q/something.

Thanks in advance!

EDIT

In the .htaccess file for the site, I have the following:

RewriteEngine on
RewriteRule ^/index.php/q/(.*) /index.php?q=$1

In the basic configuration for the site (/etc/apache2/sites-available/mysite.conf), I have:

<VirtualHost *>
        ServerAdmin me@email.com
        ServerName www.mysite.com
        DocumentRoot /var/www/www.mysite.com
        Options -Indexes +FollowSymLinks
</VirtualHost>

The index.php file is currently simply printing out the value of $_GET['q']. Now, when I visit the site http://www.mysite.com/index.php?q=12345, it displays "12345" as expected. But, when I navigate to http://www.mysite.com/index.php/q/12345, it doesn't display anything. Or, rather, it appears that the value for the query string is empty. I'm not quite sure what I'm doing incorrectly.

share|improve this question
    
Can you show us an actual configuration? For the example here, RewriteRule ^/index.php/q/(.*) /index.php?q=$1 seems to do exactly what you want...the client requests /index.php/q/something, the backend sees index.php?q=something, but there is no client redirect so nothing changes the URL visible to the client. –  larsks Apr 1 '12 at 2:08
    
It sounds like your configuration is redirecting, instead of rewriting. Check that you've configured it to simply rewrite internally. –  mgorven Apr 1 '12 at 3:49
    
I edited the post to contain the information requested. I'm not exactly sure what I'm doing wrong. –  jwir3 Apr 2 '12 at 3:22
    
I think your rewrite is fine, the problem is probably in your PHP. You need to be parsing the URL, as q/12345 has nothing in $_GET. $_GET is specifically, /?q=12345. Why don't you print_r($_REQUEST) instead to see what I mean. Also, do print_r($_SERVER['REQUEST_URI']). –  tfitzgerald Apr 2 '12 at 5:32
    
If the rewrite is in .htaccess, I think you'll want to take off the leading '/' in the RewriteRule pattern match. –  meulop Apr 2 '12 at 9:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.