Something like this should probably do the trick:

```php
$file = ( $matches[1][0]==='/' ? $webRoot : dirname($fileName) ) . $matches[1];
```