用空白变量

时间:2016-03-29 03:29:17

标签: php .htaccess mod-rewrite

如何在htaccess中重写以下网址?

1. domain.com/search.php?c=category&search=searchword&var3=variable&page=pagenumber
2. domain.com/search.php?c=category&search=searchword&var3=variable
3. domain.com/search.php?c=category&search=&var3=variable&page=pagenumber
4. domain.com/search.php?c=category&search=&var3=variable

我希望网址看起来像:

1. domain.com/search/category/searchword/variable/pagenumber
2. domain.com/search/category/searchword/variable
3. domain.com/search/category/variable/pagenumber
4. domain.com/search/category/variable

我在htaccess中使用了URL 1和2,但我需要3和4使用空白搜索变量。

htaccess的:

RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ search.php?c=$1&search=$2&var3=$3&page=$4 [L,QSA]
RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/?$ search.php?c=$1&search=$2&var3=$3[L,QSA]

0 个答案:

没有答案