如何扩展一个简单的RewriteRule

时间:2013-12-03 02:17:31

标签: apache mod-rewrite

我们正在使用以下规则来重写:

http://ourdomain/dev/client/photolibrary-europe-paris

到此:

http://ourdomain/dev/client/photolibrary.php?katid=paris

和此:

http://ourdomain/dev/client/photolibrary-europe-paris-city

到此:

http://ourdomain/dev/client/photolibrary.php?katid=paris&shootingid=city

RewriteRule ^photolibrary-([A-Za-z0-9]+)-([A-Za-z0-9]+)/?$ photolibrary.php?katid=$2 [NC,L]
RewriteRule ^photolibrary-([A-Za-z0-9]+)-([A-Za-z0-9]+)-([A-Za-z0-9]+)/?$ photolibrary.php?katid=$2&shootingid=$3 [NC,L]

但是,我们的网址有时如下:

http://ourdomain/dev/client/photolibrary-europe-paris-city-right

我们需要将其转换为:

http://ourdomain/dev/client/photolibrary.php?katid=paris&shootingid=city-right

关于我们如何实现这一目标的任何想法?非常感谢您的帮助!!

1 个答案:

答案 0 :(得分:0)

您可以将-字符包含在最后一个分组中:

RewriteRule ^photolibrary-([A-Za-z0-9]+)-([A-Za-z0-9]+)-([A-Za-z0-9-]+)/?$ photolibrary.php?katid=$2&shootingid=$3 [NC,L]

因此([A-Za-z0-9-]+)可以匹配city-right