JOURNAL ::: PICTURES ::: CODE ::: INFO ::: MEDIA ::: PORTFOLIO
WRITING ::: ABOUT ::: FUQ ::: VEGGIE ::: LINKS ::: MISC

No more question marks

Random Info #2
Wednesday, August 28, 2002

For a project I was working on, I wanted to get rid of the question mark but still pass on everything as a query string. In the end, it makes sense, but if you're having trouble getting there, this may help.

This works under Apache with mod_rewrite. In your .htaccess put the following:

RewriteEngine on
RewriteCond %{QUERY_STRING} !^.+$
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.+)$ index.php?$1 [T=application/x-httpd-php,L]

The first line turns mod_rewrite on. The second line checks to see if there is NOT a query string. The third line ensures that the URI does NOT contain index.php. (Otherwise it will send index.php as the query string when you go to the directory without any trailing characters.) If those rules match, it redirects to index.php and any characters after the directory are sent as a query string.

A couple things that took me a while to figure out:

As far as I can tell, you can't match question marks in a RewriteRule.

The part being matched (the part right after RewriteRule) does not include the directory name. So if you have http://domain.com/directory/index.html it will be index.html not /directory/index.html.

SEARCH ME

Banned from Heritage Park. Click here.

INTERESTING LINKS
Oral arguments Dec 8:
Gilmore v. Gonzales

Hemp.Net
Harmonica beatboxing
Unskilled and unaware
Vocabula
Download Firefox!
Why ternary?
InWa

SELECTED CRAP
Local currency
Fly without ID
Schmechnology
Aiding terrorism
Tea suggestions
Watching them
Democrats!
My neural code
Hobbyism
Hackers
Small claims loss
I think I was stoned

© 1997-2008 Ben Livingston. All rights reserved.