2017-08-31 40 views
1

我有一个问题,例如: 我使用3线重写如何重写规则3线1线htaccess的

RewriteRule ^category.html$ index.php?page=category&type=all&page_value=1 
RewriteRule ^category/([a-zA-Z0-9\-\_]+).html$ index.php?page=category&type=$1&page_value=1 
RewriteRule ^category/([a-zA-Z0-9\-\_]+)/([0-9]+).html$ index.php?page=category&type=$1&page_value=$2 

我能重写规则在1号线?

+1

这会变得不必要的复杂... – CBroe

回答

2

类 - 你可以这样做:

RewriteRule ^category(?:(?:/([a-zA-Z0-9\-\_]+))?(?:/([0-9]+))?)?.html index.php?page=category&type=$1&page_value=$2 

演示:http://htaccess.mwl.be?share=ea336c72-76e4-5324-863d-ce32c04573c3

但是 - 看看如何为基类,这并不值传递给您的查询字符串,以便

http://example.com/category.html

重写为

http://example.com/index.php?page=category&type=&page_value=

因此,您需要确保您的解析脚本可以使用默认参数typepage_value来处理此问题。

+0

非常感谢你 – APTX

+0

嗨@APTX - 没问题。如果此答案已解决您的问题,请点击复选标记,考虑[接受](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。这向更广泛的社区表明,您已经找到了解决方案,并为答复者和您自己提供了一些声誉。没有义务这样做。 – Bananaapple