【问题标题】:Simple Htaccess redirect not working简单的 Htaccess 重定向不起作用
【发布时间】:2012-08-01 04:40:15
【问题描述】:

由于某种原因,这不起作用...

Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /

Redirect 301 "/modules.php?name=News&file=article&sid=179" http://www.mysite.com/a/new/url

我不知道为什么...如果我用另一个不存在的 URL (/helloworld) 替换被重定向的 URL,它会很好地重定向到新的 url..

它是在抓什么东西吗?我尝试转义 (/modules.php\?name=News&file=article&sid=179) 但没有任何区别,仍然只有 404s。

感谢任何帮助!

【问题讨论】:

  • 404s?它重定向到哪个页面

标签: .htaccess url redirect


【解决方案1】:

您无法匹配 Redirect 指令中的查询字符串,您必须使用 mod_rewrite 和 %{QUERY_STRING} 变量。试试这个:

RewriteCond %{QUERY_STRING} name=News&file=article&sid=179
RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L]
# There is a ? here to prevent query strings appending -----^

【讨论】:

  • 谢谢你,好吧,终于让我走了!除了现在的 URL:mysite.com/a/new/url/?name=News&file=article&sid=179。我怎样才能让 URL 成为 /a/new/url 而不在其中粘贴旧的东西?
  • @user1556073 将 ? 添加到 /a/new/url 的末尾,如下所示:RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L]
  • 仍然做同样的事情......它将查询添加到新 URL 的末尾。我只想要简单的新 URL,就像它出现在重写规则中一样(我不希望最后的查询)。谢谢!
  • @user1556073 您已将规则更改为RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L]?请注意 url 末尾的 ?。并确保没有QSA 标志。因为当我测试该规则时,末尾没有附加任何内容。
  • 这正是我所拥有的:RewriteRule ^/?modules\.php$ mysite.com/game/32/pc/game1? [R=301,L]。我生成的 URL 如下所示:mysite.com/a/new/url/?name=News&file=article&sid=179 任何想法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-07
  • 2015-08-01
相关资源
最近更新 更多