Mod_rewrite-如何301将旧的URL重定向到新的URL [英] Mod_rewrite - how to 301 redirect an old URL to a new one

查看:72
本文介绍了Mod_rewrite-如何301将旧的URL重定向到新的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取我网站的一些旧URL并执行301重定向到新URL,因为它们已被索引,并且我们不想在更改后失去相关性.旧的URL实际上非常难看,由于某种原因,我尝试重写的所有内容均无法正常工作.在这里:

I need to grab some of my website's old URLs and do a 301 redirect to the new ones, since they are already indexed and we don't want to loose relevance after the change. The old URL is in fact very ugly and for some reason everything I try to do to rewrite it does not work. Here it is:

http://www.mywebsite.com/ExibeCurso.asp?Comando=TreinamentoGeral&codCurso=136&Titulo=Como%20Estruturar%20um%20Sistema%20Gerencial%20de%20Controles%20Organizacionais,13

基本上,我需要将其翻译为:

Basically, I need to translate it into something like:

http://www.mywebsite.com/curso/136

从旧的URL中,我需要检查用户是否键入了"ExibeCurso.asp";那么我知道我必须把他送到这里:/curso.我还必须获取querystring参数"codCurso"(136)中的整数.我必须为此使用的正则表达式是什么.我正在使用ISAPI_Rewrite 3,它基本上在IIS上实现htaccess,因此语法上应该没有区别.谢谢.

From the old URL I need to check if the user typed "ExibeCurso.asp"; then I know I must send him here: /curso. I must also grab the integer that was in the querystring parameter "codCurso" (136). What is the regular expression I must use for this. I am using ISAPI_Rewrite 3, which basically implements htaccess on IIS, so there should be no difference in terms of syntax. Thanks.

推荐答案

尝试以下规则:

RewriteCond %{QUERY_STRING} ^([^&]*&)*codCurso=([0-9]+)(&.*)?$
RewriteRule ^/ExibeCurso\.asp$ /curso/%2? [L,R=301]

但是我不确定ISAPI Rewrite是否要求模式以斜杠开头.

But I’m not sure whether ISAPI Rewrite requires the pattern to begin with a slash.

这篇关于Mod_rewrite-如何301将旧的URL重定向到新的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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