Useful for Symfony2 or Silex as they load an instance of the app in Twig, this snippet allows to check if you're currently at its root, no matter it's in a subdirectory on your web server or not.

{% if app.request.getRequestURI()|rtrim('/') == app.request.getBasePath() %}
    {# do something #}
{% endif %}