【问题标题】:301 Redirect with .Htaccess使用 .Htaccess 进行 301 重定向
【发布时间】:2014-12-10 10:30:25
【问题描述】:

我的 htaccess 文件有以下几行:

RewriteRule ^newlink ?do=something
Redirect 301 /oldlink/ /newlink

当我写 http://www.example.com/oldlink/ 时,浏览器会重定向到 http://www.example.com/newlink?do=something

如何修剪 ?do=something ??

它应该重定向到/newlink;不是 /newlink?do=something

【问题讨论】:

标签: .htaccess redirect http-status-code-301


【解决方案1】:

不要将mod_rewrite 规则与mod_alias 规则混用。像这样使用mod_rewrite 本身保持你的规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+newlink[\s?] [NC]
RewriteRule ^ /?do=something [L,NC,QSA]

RewriteCond %{THE_REQUEST} \s/+oldlink/?[\s?] [NC]    
RewriteRule ^ /newlink? [L,NC,R=302]

? 最后用于修剪任何现有的查询字符串。

【讨论】:

  • 你确定吗?它导致 500 Internal Server Error...(/content/ 与 /content 不同;因为我将 /content 用于类别主页;/content/link = 详细页面)
  • 谢谢你,anubhava...但是,如果我有很多(100+)个类别呢?例如 /content/、/gallery/、/collections/、/news/ 等...不是在 htaccess 中造成太多行吗?我不能通过 301 做吗?
  • 我将只对一些旧网址使用 301
  • 最好编辑您的问题并将其添加到您的要求中。 Stachoverflow 模组不喜欢从 cmets 部分更改问题。
  • 你能再看看吗:/
猜你喜欢
  • 2017-04-15
  • 2015-08-15
  • 2014-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多