我想知道是否可以检查PHP.中的Apache和IIS上是否启用了mod_rewrite
存在用于IIS的ModRewrite。检查它,here。
所以,我正在寻找一个在Apache和IIS上检查mod_rewrite的PHP脚本。
有没有人知道或者会写这样的脚本?
特别是对于微软的IIS。
谢谢!
发布于 2012-01-27 00:30:53
如果你使用的是mod_php,你可以使用apache_get_modules()。这将返回一个包含所有已启用模块的数组,因此要检查是否启用了mod_rewrite,您可以简单地执行以下操作
in_array('mod_rewrite', apache_get_modules());不幸的是,您最有可能尝试使用CGI来完成此任务,这使得它变得有点困难。
不过,您可以使用以下命令对其进行测试
strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false如果上述条件的计算结果为true,则启用mod_write。
发布于 2012-01-27 00:28:29
复制这段代码并运行它来找出答案。
<?php
if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
$res = 'Module Unavailable';
if(in_array('mod_rewrite',apache_get_modules()))
$res = 'Module Available';
?>
<html>
<head>
<title>A mod_rewrite availability check !</title></head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>发布于 2013-01-17 17:20:01
### .htaccess
<IfModule mod_rewrite.c>
# Tell PHP that the mod_rewrite module is ENABLED.
SetEnv HTTP_MOD_REWRITE On
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# The rest of your rewrite rules here
</IfModule>然后,您可以签入PHP代码,以便
array_key_exists('HTTP_MOD_REWRITE', $_SERVER);不知道这是否也适用于IIS (我无法检查),但可能性很大。
https://stackoverflow.com/questions/9021425
复制相似问题