简体   繁体   English

Mod_rewrite-如何将旧网址重定向到新网址301

[英]Mod_rewrite - how to 301 redirect an old URL to a new one

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. 我需要获取网站的一些旧URL并执行301重定向到新URL,因为它们已被索引,并且我们不想在更改后失去相关性。 The old URL is in fact very ugly and for some reason everything I try to do to rewrite it does not work. 旧的URL实际上非常难看,由于某种原因,我尝试重写的所有内容均无法正常工作。 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

From the old URL I need to check if the user typed "ExibeCurso.asp"; 从旧的URL,我需要检查用户是否键入了“ ExibeCurso.asp”; then I know I must send him here: /curso. 那么我知道我必须把他送到这里:/ curso。 I must also grab the integer that was in the querystring parameter "codCurso" (136). 我还必须获取querystring参数“ 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. 我正在使用ISAPI_Rewrite 3,它基本上在IIS上实现htaccess,因此语法上应该没有区别。 Thanks. 谢谢。

Try this rule: 尝试以下规则:

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

But I'm not sure whether ISAPI Rewrite requires the pattern to begin with a slash. 但是我不确定ISAPI Rewrite是否要求模式以斜杠开头。

Off the top of my head, something like this should work: 在我的头顶上,这样的事情应该起作用:

RewriteRule ^ExibeCurso.asp(.*)$ http://www.mywebsite.com/curso/$1 [L,R=301]

That would at least send the traffic to /curso/ with all parameters attached. 至少会将所有附加参数的流量发送到/ curso /。 Maybe it's best to process it from there. 也许最好从那里进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM