CSS según URL

StackOverflow

PHP

$directoryURI = $_SERVER['REQUEST_URI'];
$path = parse_url($directoryURI, PHP_URL_PATH);
$components = explode('/', $path);
$first_part = $components[1];

HTML/PHP

<ul id="mainnav">
    <li class="<?php if ($first_part=="") {echo "active"; } ?>"><a href="#">Home</a></li>
    <li class="<?php if ($first_part=="tutorials") {echo "active"; } ?>"><a href="#">Tutorials</a></li>
    <li class="<?php if ($first_part=="resources") {echo "active"; } ?>"><a href="#">Resources</a></li>
    <li class="<?php if ($first_part=="library") {echo "active"; } ?>"><a href="#">Library</a></li>
    <li class="<?php if ($first_part=="our-projects") {echo "active"; } ?>"><a href="#">Our Projects</a></li>
    <li class="<?php if ($first_part=="community") {echo "active"; } ?>"><a href="#">Community</a></li>
</ul>