Wednesday 29 April 2009

Hiding the WCF .svc extension on IIS 5 or 6

If you're setting up a WCF web service, its nicer to present a URL that does not have the .svc extension in it, i.e.

http://moviesite.com/movies/123

Instead of
http://moviesite.com/service.svc/movies/123


A simple way of achieving this on IIS versions 5 or 6 is using the free ISAPI Rewrite tool, with the following configuration:

# Don't rewrite url's that already contain .svc.


RewriteRule .*\.svc.* - [L]


# Rewrite requests for host
moviesite.com to be moviesite.com/service.svc/whatever.

RewriteCond %{HTTP:Host}
moviesite.com

RewriteRule ^/(.*)$ /service.svc/$1 [L]

No comments: