### .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>
/**
* --------------------------------------------------------------
* MOD REWRITE CHECK
* --------------------------------------------------------------
* - By A H Abid
* Define Constant for MOD REWRITE
*
* Check if server allows MOD REWRITE. Checks for both
* Apache and IIS.
*
*/
if( function_exists('apache_get_modules') && in_array('mod_rewrite',apache_get_modules()) )
$mod_rewrite = TRUE;
elseif( isset($_SERVER['IIS_UrlRewriteModule']) )
$mod_rewrite = TRUE;
else
$mod_rewrite = FALSE;
define('MOD_REWRITE', $mod_rewrite);
它可以在我的本地机器上工作,也可以在基于 IIS 的网络主机上工作。但是,在一个特定的 Apache 服务器上,它不能在 Apache 上工作,因为 Apache _ get _ module ()被禁用了,但是在那个服务器上启用了 mod _ rewrite。
require 'vendor/autoload.php';
use HtaccessCapabilityTester\HtaccessCapabilityTester;
$hct = new HtaccessCapabilityTester($baseDir, $baseUrl);
if ($hct->rewriteWorks()) {
// rewriting works
}