从 301 重定向中删除查询字符串 [英] Remove query strings from 301 redirect

查看:24
本文介绍了从 301 重定向中删除查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力为最初使用查询字符串构建的网站创建适当的 301 重定向.旧的 URL 结构如下所示:

I am struggling to create appropriate 301 redirects for a site that was originally built using query strings. The old URL structure looks like this:

http://www.oldsite.com/about/index.cfm?fuseaction=cor_av&artID=5049

我想将整个子文件夹(名为about")重定向到新域上的新页面.新域的 URL 如下所示:

I want to redirect the entire subfolder (named 'about') to a new page on the new domain. The new domain's URL looks like this:

http://www.newsite.com/info

所以,我设置了一个如下所示的重定向:

So, I set up a redirect that looks like this:

redirectMatch 301 ^/about/ http://www.newsite.com/info  

它重定向得很好,但它保留了原始 URL 字符串的附加,因此新 URL 在浏览器中最终看起来像这样:

It is redirecting just fine, but it's keeping the original URL string attached, so the new URL ends up looking like this in a browser:

http://www.newsite.com/info/?fuseaction=cor_av&artID=5049 

我绝对不是一个 Apache/301 专家,不知道如何解决这个问题.我只想从 ?

I'm definitely not enough of an Apache/301 expert ot know how to fix this. I just want to strip off everything from the ? on.

非常感谢您的帮助.

推荐答案

两个选项:

redirectMatch 301 ^/about/ http://www.newsite.com/info? 

或:

RewriteEngine on
RewriteRule ^about/(.*) http://www.newsite.com/info? [L,R=301]

最后的问号似乎是关键点.第二个看起来更简洁(第一个在 URL 末尾留下一个问号)

question mark at the end seems to be the critical bit. Second one looks a little cleaner (first leaves a question mark at the end of your URL)

这篇关于从 301 重定向中删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆