【问题标题】:htaccess redirecting from rewritten dynamic urls to new dynamic urlshtaccess 从重写的动态 url 重定向到新的动态 url
【发布时间】:2012-09-28 18:19:08
【问题描述】:

我遇到了一个非常独特的问题,希望有人能提供帮助!

所以我们最近创建了一个新的电子商务网站,我们让它上线了,一切都运行良好,但是当我们从旧页面实施 301 时,我们得到了一些奇怪的东西

所以下面的代码确实有效

Redirect 301 /directory/ http://mysite.com/index.php?cat=1

这段代码没有

Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2

我尝试执行此重定向时的输出是“指定的参数无效!”在空白网页和地址栏中有这个

http://mysite.com/index.php?cat=1/sub_directory/

我们认为问题可能是因为我们的旧页面是动态的,但 mod_rewrite 用于创建更可读的 url,我们还删除了所有旧文件,因为它们干扰了我们的新页面渲染

任何帮助将不胜感激!

谢谢

【问题讨论】:

    标签: .htaccess redirect dynamic-url


    【解决方案1】:

    这很奇怪,因为重定向应该只匹配列出的特定 url,而它的行为类似于 rewriterule 并且部分匹配子目录 url 与第一条规则..

    尝试将更具体的规则置于不太具体的规则之上,如下所示:

    Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2
    Redirect 301 /directory/ http://mysite.com/index.php?cat=1
    

    这样更具体的规则将首先被命中,而 /directory/ only 规则只有在上面更具体的匹配失败时才会匹配

    或者,您可以尝试 RewriteRules:

    RewriteRule ^directory/$ http://mysite.com/index.php?cat=1 [R=301,NC,L]
    RewriteRule ^directory/sub_directory/$ http://mysite.com/index.php?cat=2 [R=301,NC,L]
    

    ^ 和 $ 锚点应该防止任何不需要的部分匹配

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 2021-06-30
      • 2016-09-18
      • 2021-04-10
      相关资源
      最近更新 更多