Search for non-existing tags shows all entries I have 3 groups of tags that redirect to the same template. tags/index.html. All the routing and linking those tags to their group page works well.

&lt;a href="{{ siteUrl }}taggroup/{{ tag.slug }}"

The problem I have is that when I try to enter a tag that doesn't exist on the address bar (e.g., http://sitename/taggroup/unknowntag) I get all entries displayed.

Here's my tags/index.html code: 

{% if not tag %}
    {% exit 404 %}
{% endif %}

{% set tag = craft.tags.slug(tag).first %}

{% set entries = craft.entries.relatedTo(tag).order('title').limit(null) %}

 {% if entries | length %}

  {% for entry in entries %}

    &lt;!-- Code Here --&gt;

  {% endfor %}

  {% else %}

   &lt;!-- No Tag Code Here --&gt;

 {% endif %}


What Am I doing wrong? Thanks in advance.
That is only logical. Your tag will be null so your query is actually 
{% set entries = craft.entries.relatedTo(null).order('title').limit(null) %} and that results in 
{% set entries = craft.entries.order('title').limit(null) %}
So in the end you will fetch all entries. 
This is what you need 

{% set tag = craft.tags.slug(tag).first %}
&lt;!-- check if the tag exists --&gt;
{% if tag %}
    &lt;!-- the length filter actually fetches all entries -&gt; executes the query and caches all entries
    so you can just fetch them in the beginning. You'll gain no performance boost with that filter --&gt;
    {% set entries = craft.entries.relatedTo(tag).order('title').limit(null).find() %}
    {% if entries %}
        {% for entry in entries %}
            &lt;!-- code here you fetched entries --&gt;
        {% endfor %}
    {% else %}
        &lt;!-- you have a tag but no entries related to that tag --&gt;
    {% endif %}
{% else %}
    &lt;!-- you have no tag -&gt; you won't find any entries --&gt;
{% endif %}