.htaccess mod_rewrite可选参数

时间:2012-12-14 14:39:10

标签: .htaccess mod-rewrite

为了拥有不错的网址,我编辑了我的.htacces文件

domain.com/category/content

应重定向到

domain.com/index.php?category=cat&content=cont

这行适用于此行

RewriteRule ^([^/]*)/([^/]*)$ /index.php?category=$1&content=$2 [L]

domain.com/category

应重定向到

domain.com/index.php?category=cat

显示整个类别的内容

我确信这很容易解决,但这对我来说很困惑。

1 个答案:

答案 0 :(得分:0)

使用2条规则:

RewriteRule ^([^/]+)/([^/]+)$ /index.php?category=$1&content=$2 [L]
RewriteCond %{REQUEST_URI} !/index.php
RewriteRule ^([^/]+)/?$ /index.php?category=$1 [L]