3

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

1 Answer 1

9

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);
Sign up to request clarification or add additional context in comments.

4 Comments

Wow, nice one, I wouldn't have thought of that. btw. You could use ob_get_clean() function.
But ob_get_clean doesn’t end the buffer so you would need another ob_end_* call anyway.
It actually does. In documentation is: ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().
As a note, this doesn't appear to work when PHP is run FCGI. Not seeing anything as far as apache modules go in INFO_MODULES.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.