【问题标题】:How do I redirect a URL with a parameter to a clean URL in htaccess?如何将带有参数的 URL 重定向到 htaccess 中的干净 URL?
【发布时间】:2015-06-19 19:29:13
【问题描述】:

我正在尝试 301 重定向几个带有参数的 URL,以清除 URL。

例如,我正在尝试重定向: http://example.com/news/news.php?id=1234http://example.com/posts/vanity-url.php

这是我的代码:

RewriteCond %{QUERY_STRING} id=1234
RewriteRule ^news/news\.php$ /posts/vanity-url.php [L,R=301]

我觉得我很接近这段代码,但它会将我重定向到: http://example.com/posts/vanity-url.php?id=1234 我不知道为什么会这样。

如果有任何帮助,我将不胜感激。谢谢!

【问题讨论】:

    标签: .htaccess mod-rewrite redirect


    【解决方案1】:

    在删除查询字符串后添加问号

    RewriteRule ^news/news\.php$ /posts/vanity-url.php? [L,R=301]
    

    【讨论】:

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