0

我有一些 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]

但是得到内部服务器错误。

4

1 回答 1

0

我相信您正在错误地处理查询字符串。

有关使用 RewriteCond 处理查询字符串的一些示例,请参阅以下博客文章。

  1. http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects
  2. 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 必须在重写规则中排在第一位(或置于重写条件中),而不是像您拥有的那样排在第二位。

于 2012-07-08T06:37:21.507 回答