<p>This will redirect all queries but urls containing: 
<code>api</code> or <code>robots</code> or <code>utm_source</code> strings</p>

<pre><code>return array(
   '^(?!.*(api|robots|utm_source)).*$' =&gt; ['template' =&gt; 'index']
);
</code></pre>

CC BY-SA 4.0
2019-06-20T09:26:34.150Z
2019-06-20T09:26:34.150Z
HendrikEng
<p>I have a defined in routes.php a regex that redirects all queries but api to my index template:</p>

<pre><code>return array(
   '&lt;url:(?!api).*&gt;' =&gt; ['template' =&gt; 'index']
);
</code></pre>

<p>I'm trying to exclude robots.txt as well as Google Analytics which is <code>utm_source=analytics_test&amp;utm_medium=referral</code> I've tried the following but it's not quite right:</p>

<pre><code>return array(
   '&lt;url:^(?!api|robots|utm_source)(.*)$&gt;' =&gt; ['template' =&gt; 'index']
);
</code></pre>

<redirect>
Redirect all but certain requests to index
# Redirect all but certain requests to index

(Asked by: username_0 on 2019-06-17)

I have a defined in routes.php a regex that redirects all queries but api to my index template:
return array(
   '' => ['template' => 'index']
);

I'm trying to exclude robots.txt as well as Google Analytics which is utm_source=analytics_test&utm_medium=referral I've tried the following but it's not quite right:
return array(
   '' => ['template' => 'index']
);

**Tags:** redirect

---

## 1 answers

### Answer by username_1 on 2019-06-20. Score: 4 | Accepted answer

This will redirect all queries but urls containing: 
api or robots or utm_source strings
return array(
   '^(?!.*(api|robots|utm_source)).*$' => ['template' => 'index']
);


---

