我正在努力检查评论页面的网址结构,可以按城市,县,星级和技术人员进行过滤。我想让页面看起来像是静态HTML页面,以及用连字符替换加号。 我的目标: - 应用新样式URL而不修改评论页面,只修改htaccess文件 - 设置从旧样式URL到新样式URL的301重定向 - 转换为连字符
目前,审核网址如下所示:
domain.com/reviews/?city=City+Name
domain.com/reviews/?city=City+Name&page=2
domain.com/reviews/?county=County+Name
domain.com/reviews/?county=County+Name&page=2
domain.com/reviews/?stars=4
domain.com/reviews/?stars=4&page=2
domain.com/reviews/?tech=Tech+Name
domain.com/reviews/?tech=Tech+Name&page=2
我的目标是让它们看起来像这样(以及301新样式网址的旧样式网址):
domain.com/reviews/city/City-Name.html
domain.com/reviews/city/City-Name/page/2.html
domain.com/reviews/county/County-Name.html
domain.com/reviews/county/County-Name/page/2.html
domain.com/reviews/stars/4.html
domain.com/reviews/stars/4/page/2.html
domain.com/reviews/tech/Tech-Name.html
domain.com/reviews/tech/Tech-Name/page/2.html
城市,县和科技名称并不总是包含优势(即波士顿vs新约克),有些还有一个以上。目前,这是我必须使用新样式URL掩盖旧样式URL(这很好用btw):
##FIRST PAGE REVIEWS (ie. reviews/city/city-name.html)
RewriteRule ^reviews/(.*)/(.*)\-(.*)\-(.*)\-(.*)\-(.*)\.html "/reviews/?$1=$2+$3+$4+$5+$6" [NC,L]
RewriteRule ^reviews/(.*)/(.*)\-(.*)\-(.*)\-(.*)\.html "/reviews/?$1=$2+$3+$4+$5" [NC,L]
RewriteRule ^reviews/(.*)/(.*)\-(.*)\-(.*)\.html "/reviews/?$1=$2+$3+$4" [NC,L]
RewriteRule ^reviews/(.*)/(.*)\-(.*)\.html "/reviews/?$1=$2+$3" [NC,L]
RewriteRule ^reviews/(.*)/(.*)\.html "/reviews/?$1=$2" [NC,L]
##PAGINATED REVIEWS (ie. reviews/city/city-name/page/2.html)
RewriteRule ^reviews/(.*)/(.*)\-(.*)\-(.*)\-(.*)\-(.*)/page/(.*)\.html "/reviews/?$1=$2+$3+$4+$5+$6&page=$7" [NC,L]
RewriteRule ^reviews/(.*)/(.*)\-(.*)\-(.*)\-(.*)/page/(.*)\.html "/reviews/?$1=$2+$3+$4+$5&page=$6" [NC,L]
RewriteRule ^reviews/(.*)/(.*)\-(.*)\-(.*)/page/(.*)\.html "/reviews/?$1=$2+$3+$4&page=$5" [NC,L]
RewriteRule ^reviews/(.*)/(.*)\-(.*)/page/(.*)\.html "/reviews/?$1=$2+$3&page=$4" [NC,L]
RewriteRule ^reviews/(.*)/(.*)/page/(.*)\.html "/reviews/?$1=$2&page=$3" [NC,L]
我遇到问题的部分是将OLD样式的URL转换为新样式的URL。这就是我到目前为止所做的:
RewriteCond %{QUERY_STRING} (.*)=(.*) [NC]
RewriteRule ^reviews/(.*) /reviews/%1/%2.html? [NS,R=301,NC]
RewriteCond %{QUERY_STRING} (.*)=(.*)&page=(.*) [NC]
RewriteRule ^reviews/(.*) /reviews/%1/%2/page/%3.html? [NS,R=301,NC]
当我尝试这个时,FireFox会给我“页面没有正确重定向”错误。有什么想法吗?
答案 0 :(得分:0)
是的,这可能是一个无限循环。请改用 THE_REQUEST 来检查request line:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?([^=]+)=([^\ ]*)&page=([^\ ]*) [NC]
RewriteRule ^reviews/ /reviews/%1/%2/page/%3.html? [NS,R=301,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?([^=]+)=([^\ ]*)
RewriteRule ^reviews/ /reviews/%1/%2.html? [NS,R=301,NC]
请注意,如果参数的数量或顺序与此不同,则会失败。