【发布时间】:2012-04-27 11:04:39
【问题描述】:
我的 htaccess 文件中有一些 mod_rewrite 规则可以将不存在的页面重定向到默认页面,如下所示:
http://domain.tld/category1/subcategoryXhttp://domain.tld/category1/subcategoryX/http://domain.tld/category1/subcategoryX/property1http://domain.tld/category1/subcategoryX/property1/
全部重定向到
http://domain.tld/category1/subcategoryX/property1/value1
我正在执行此重定向,因为子类别和属性没有页面,只有值有。
这些是规则:
RewriteRule ^category1/[a-z-]+$ http://%{HTTP_HOST}%{REQUEST_URI}/property1/value1 [R,NC,L]
RewriteRule ^category1/[a-z-]+/$ http://%{HTTP_HOST}%{REQUEST_URI}property1/value1 [R,NC,L]
RewriteRule ^category1/[a-z-]+/property1$ http://%{HTTP_HOST}%{REQUEST_URI}/value1 [R,NC,L]
RewriteRule ^category1/[a-z-]+/property1/$ http://%{HTTP_HOST}%{REQUEST_URI}value1 [R,NC,L]
规则是有效的,但它们有点冗长。有什么技巧可以压缩规则吗?前两个的区别只是结束斜线,后两个也是。
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting rewrite redirect