【问题标题】:htaccess redirect dynamic url to static urlhtaccess 将动态 url 重定向到静态 url
【发布时间】:2012-07-08 06:30:06
【问题描述】:

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

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

【问题讨论】:

    标签: php apache .htaccess redirect


    【解决方案1】:

    我认为您处理查询字符串不正确。

    有关使用 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 必须在重写规则中排在第一位(或置于重写条件中),而不是像您拥有的那样排在第二位。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-15
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多