views:

13

answers:

2

I want an htaccess rewrite rule to grab everything past the host name and use it as an argument. For example, I want http://example.com/one to be handled by http://example.com/category.php?cat=one

I think it should be simple, but I can't quite find the combination. Thanks

A: 

Try something like this:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ category.php?cat=$0 [B]

If you want to pass the query string along too, be sure to change the B flag to B,QSA, but be aware that someone could then pass the GET argument cat, which would override what you set in the rewrite. There are some workarounds to that situation if you need them, but otherwise that should do it for you.

Tim Stone
Thank you, Tim. I can't find the [B] flag documented anywhere. Can you explain it or point me to some info about it?
Eric
Tim Stone
A: 

This is what I came up with:

RewriteRule ^/?([^\./]*)[:;,\.]*$ category.php?cat=$1 [L,NS]

Anybody see any way to improve it?

Eric