Tag archives: rewriting

How to check if Apache's mod_rewrite is installed? | PHP Snippet

Hi everyone!

This is a snippet (function) that lets you know if the mod_rewrite of Apache is installed on a Web server.


<?php
/**
 * Check if Apache's mod_rewrite is installed.
 * 
 * @return boolean
 */
function isRewriteMod()
{
    if (function_exists('apache_get_modules'))
    {
        $aMods = apache_get_modules();
        $bIsRewrite = in_array('mod_rewrite', $aMods);
    }
    else
    {
        $bIsRewrite = (strtolower(getenv('HTTP_MOD_REWRITE')) == 'on');
    }

    return $bIsRewrite;
}
?>

How to use this?

Very simple, just look this example below:


if (!isRewriteMod()) exit('Please install Apache mod_rewrite module.');

Good code! ;-)

Continue reading