开发者

htaccess rewriterule for grabbing everything past hostname

开发者 https://www.devze.com 2023-01-06 17:20 出处:网络
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.ph

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消