我有一些url重写类似的东西:
RewriteRule ^futbol-video/([^/]*)-([^-]*)'.html$ /html/video.php?text=$1&id=$2 [L]
RewriteRule ^futbol-takimi/([^/]*)-([^-]*)'.html$ /html/takim.php?text=$1&id=$2 [L]
我正在尝试将动态查询重定向到静态页面。我尝试了下面的方法,但每次都会出现内部服务器错误。我应该如何编写规则表单301重定向?
我第一次尝试:
RewriteRule ^futbol-video/([^/]*)-([^-]*)'.html$ /html/video.php?text=$1&id=$2 [R=301,L]
RewriteRule ^futbol-takimi/([^/]*)-([^-]*)'.html$ /html/takim.php?text=$1&id=$2 [R=301,L]
但是获取内部服务器错误。
我认为您处理查询字符串不正确。
有关使用RewriteCond处理查询字符串的一些示例,请参阅以下博客文章。
- http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects
- http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/
博客示例:
#Keep original query (default behavior)
RewriteRule ^page'.php$ /target.php [L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php?foo=bar
#Discard original query
RewriteRule ^page'.php$ /target.php? [L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php
#Replace original query
RewriteRule ^page'.php$ /target.php?bar=baz [L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php?bar=baz
#Append new query to original query
RewriteRule ^page'.php$ /target.php?bar=baz [QSA,L]
# from http://example.com/page.php?foo=bar
# to http://example.com/target.php?foo=bar&bar=baz
编辑此外,如果您正试图将带有查询字符串的url重定向到静态页面,则带有查询串的url在重写规则中必须排在第一位(或置于重写条件中),而不是像您那样排在第二位。