htaccess rewriterule for grabbing everything past hostname
I want an htaccess rewrite rule to grab everything past the host name and use it as an开发者_Go百科 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
This is what I came up with:
RewriteRule ^/?([^\./]*)[:;,\.]*$ category.php?cat=$1 [L,NS]
Anybody see any way to improve it?
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.
精彩评论