I have seen several questions similar and tried all solutions but at a loss. I need to redirect
example.com/products.asp?lob=health
to
example.com/services/healthcare/
I need to do this for several lob=different value. Is there a way I can redirect each url. Maybe do some kind of rewrite condition on lob but if the value of lob = health, redirect here. If it equals home, redirect somewhere else?
Not sure this is the "correct" way to do it but it works.
RewriteCond %{QUERY_STRING} ^lob=value1$ [NC]
RewriteRule ^products.asp$ http://example.org/sample/one/? [R=301,L]
And then for a different value:
RewriteCond %{QUERY_STRING} ^lob=value2$ [NC]
RewriteRule ^products.asp$ http://example.org/sample/two/? [R=301,L]
And then for everything that doesn't match a value:
RewriteRule ^products\.asp$ [insert new url here] [R=301,L]
The last example also works if you just want to redirect a .asp url to .php. Keep in mind that I have other conditions and rules that are removing the .php extension and adding a / to all files:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
If just looking at a querystring value and then redirecting, try...
Dim theVal, newURL
If Request("lob") <> "" Then
theValue = LCase(Request("lob"))
Else
theValue = "none"
End If
Select Case theValue
Case "health"
newURL = "example.com/services/healthcare/"
Case "law"
newURL = "example.com/services/legal/"
Case Else
newURL = "example.com/services/listing/"
End Select
Response.Redirect newURL
Hope this helps.