views:

317

answers:

2

Hi, 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

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.

A: 

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. Maybe it's best to process it from there.

deceze
+1  A: 

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.

Gumbo
Marcos Buarque
hum, I think ISAPI Rewrite works exactly like this... Abraços.
Marcos Buarque