views:

209

answers:

2

Is it possible to detect mod_rewrite in PHP when function apache_get_modules() is not available?

A: 

You can check if the rewrite.load file exists in the Apache mods-enable directory. In my Ubuntu system this file is located at /etc/apache2/mods-enabled/rewrite.load

When the module is disabled, the file is located at mods-available instead.

danielrmt
Note that `mod_rewrite` can be included in an infinite number of locations, including `httpd.conf` itself. This'll be a solution only in Ubuntu and if the user is using Ubuntu's `a2enmod` function.
ceejayoz
+1  A: 

You could analyze the output of phpinfo():

ob_start();
phpinfo(INFO_MODULES);
$contents = ob_get_contents();
ob_end_clean();
var_dump(strpos($contents, 'mod_rewrite') !== false);
Gumbo
Wow, nice one, I wouldn't have thought of that. btw. You could use ob_get_clean() function.
tomp
But `ob_get_clean` doesn’t end the buffer so you would need another `ob_end_*` call anyway.
Gumbo
It actually does. In documentation is: ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().
tomp
Ah, you’re right. I should read the manual more carefully.
Gumbo
wow what a solution!
thephpdeveloper