使用此选项 :
以 < 坚固>.ht access 强>
<IfModule mod_rewrite.c>
# inform php that mod_rewrite is enabled
SetEnv HTTP_MOD_REWRITE on
...
以 < 强度 > PHP 强度 > :
$mod_rewrite = FALSE;
if (function_exists("apache_get_modules")) {
$modules = apache_get_modules();
$mod_rewrite = in_array("mod_rewrite",$modules);
}
if (!isset($mod_rewrite) && isset($_SERVER["HTTP_MOD_REWRITE"])) {
$mod_rewrite = ($_SERVER["HTTP_MOD_REWRITE"]=="on" ? TRUE : FALSE);
}
if (!isset($mod_rewrite)) {
// last solution; call a specific page as "mod-rewrite" have been enabled; based on result, we decide.
$result = file_get_contents("http://somepage.com/test_mod_rewrite");
$mod_rewrite = ($result=="ok" ? TRUE : FALSE);
}
The first (apache) can be disabled by server, the second custom one will exist in $_SERVER only if mod_env is installed.
So what i think as best solution is to create a fake url redirection in your .htaccess that points to some file of yours (that return simply an "ok") and call that with the redirection from a .php; if returns "ok", you can use clean urls...
The redirection code in .htaccess might looks like:
<IfModule mod_rewrite.c>
...
RewriteEngine on
# fake rule to verify if mod rewriting works (if there are unbearable restrictions..)
RewriteRule ^test_mod_rewrite/?$ index.php?type=test_mod_rewrite [NC,L]