<p>You could use the Craft/Twig <code>|replace</code> filter, which supports <a href="http://regexr.com/" rel="nofollow noreferrer">regex</a> replacements.</p>

<p>Something like:</p>

<pre><code>{% set handle = entry.section.handle %}

{% if handle == 'subSiteSectionHandle %}
    {% set newUrl = entry.url|replace('/regexMatchPattern/', 'replacedWith') %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2017-01-10T17:01:06.810Z
great - works 100% - using {% set newUrl = entry.url|replace(craft.request.serverName, 'newhostname') %}
mmc501
CC BY-SA 3.0
2017-01-10T00:31:03.823Z
2017-01-10T00:31:03.823Z
Brad Bell
<p>I have a group website which has a main site and 3 sub sites all within 1 Craft Installation.
Each sub site has its own Structure Section for Content.</p>

<p>I am adding a Group Wide Search to the main site and sub sites.
Sub sites are accessed by subdomain of main site - e.g.  property.domain.com agents.domain.com</p>

<p>On a sitewide search if I get results from the subsites the entry.url will just contain the domain from the site it is being searched for.</p>

<p>So for my search results - I will check the handle of the entry to see if it is from the subsites - and then if possible replace the domain.</p>

<p>I can get the handle with:</p>

<pre><code>{% set handle = entry.section.handle %}
</code></pre>

<p>Is there a handy way to replace the domain?</p>

<entries><entry><search>
Change domain in entry.url
# Change domain in entry.url

(Asked by: username_0 on 2017-01-09)

I have a group website which has a main site and 3 sub sites all within 1 Craft Installation.
Each sub site has its own Structure Section for Content.
I am adding a Group Wide Search to the main site and sub sites.
Sub sites are accessed by subdomain of main site - e.g.  property.domain.com agents.domain.com
On a sitewide search if I get results from the subsites the entry.url will just contain the domain from the site it is being searched for.
So for my search results - I will check the handle of the entry to see if it is from the subsites - and then if possible replace the domain.
I can get the handle with:
{% set handle = entry.section.handle %}

Is there a handy way to replace the domain?

**Tags:** entries, entry, search

---

## 1 answers

### Answer by username_1 on 2017-01-10. Score: 1 | Accepted answer

You could use the Craft/Twig |replace filter, which supports regex replacements.
Something like:
{% set handle = entry.section.handle %}

{% if handle == 'subSiteSectionHandle %}
    {% set newUrl = entry.url|replace('/regexMatchPattern/', 'replacedWith') %}
{% endif %}

> **Comments:**
> **username_0**: great - works 100% - using {% set newUrl = entry.url|replace(craft.request.serverName, 'newhostname') %}  

---

