Htaccess在最后一次斜线后获得最后一个字

时间:2013-03-11 17:02:21

标签: .htaccess url mod-rewrite

我怎样才能获得

http://www.example.com/aaa/bbb/ccc

http://www.example.com/index.php?cat=ccc

也希望它适用于像

这样的情况
http://www.example.com/aaa
http://www.example.com/aaa/

将是

http://www.example.com/index.php?cat=aaa

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI}  .*/([^/]+)/?     [NC]
RewriteCond %{REQUEST_URI}  !index\.php      [NC]
RewriteRule  .*      /index.php?cat=%1 [L,NC,QSA]

静默地映射:

http://www.example.com/any/number/of/folders/LastFolder

要:

http://www.example.com/index.php?cat=LastFolder

对于永久性和可见的重定向,请将[L,NC,QSA]替换为[R=301,L,NC,QSA]