目前,我在.htaccess中获得了此重写规则,以便将[value]
中的http://www.site.com/[value]
传递给/page?q=[value]
RewriteRule ^([a-zA-Z0-9_-]+)$ page?q=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ page?q=$1
我如何能够实现以下额外重写:
http://www.site.com/foo/1
- > http://www.site.com/page?param=1
http://www.site.com/bar/1
- > http://www.site.com/page?param2=1
http://www.site.com/baz/1
- > http://www.site.com/page2?param=1
答案 0 :(得分:1)
通过在旧版本之前添加更多重写,因为级别更高,规则应该在旧版本之前:
RewriteRule ^bar/([1-9])$ page?param2=$1 [L]
RewriteRule ^baz/([1-9])$ page2?param=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([1-9])$ page?param=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ page?q=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)$ page?q=$1 [L]