.htaccess搜索页面重写

时间:2012-07-24 10:15:35

标签: .htaccess redirect rewrite

我有一个网站www.domain.com/jeeves/。我希望网站上的搜索看起来像这样:

http://www.domain.com/jeeves/results/[search_term_here]/[page_number_here]

在搜索中,我希望他们能够转到第1页。在nextprevious等,浏览页码。

htaccess的:

 # rewrite all URL's of the format I want to point at my php page with params
 RewriteRule ^results/([A-Za-z0-9]+)$/([0-9]+)$ http://www.domain.com/jeeves/search.php?s=$1&page=$2 [NC,L]

 # rewrite initial search query to the first page of results
 RewriteCond %{QUERY_STRING} s=([^&]*)
 RewriteRule ^search http://www.domain.com/jeeves/results/%1/1? [NC,R=301]

这似乎不起作用 - 任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

你的第一个正则表达式不正确:^结果/([A-Za-z0-9] +) $ /([0-9] +)$
试试这个:

RewriteRule ^jeeves/results/([A-Za-z0-9]+)/([0-9]+)/?$ /jeeves/search.php?s=$1&page=$2 [NC,L]
RewriteCond %{QUERY_STRING} s=([^&]+)
RewriteRule ^jeeves/search /jeeves/results/%1/1? [NC,R=301]`enter code here`