Instead of replace, why not use urlencode? When I tested this I got an error that my search term was missing, but this works:

```
{$site_root_path}search.php?u={$user}&n=twitter&c=searches&k={$h->hashtag|urlencode}&q={$h->hashtag|urlencode}
```

Look okay?