PDA

View Full Version : mod_rewrite


edbr
11-06-2013, 08:14 AM
I have backed my self up a tree here. I have a script that is failing as it cannot detect if mod_rewrite is installed. It is not a uniqque problem it seems , but i have a test but cannot adapt it for a sub folder , the following is a test for the root directory. can any one see the error , or rather whare i must change the path for a folder??

.htaccess
<IfModule mod_rewrite.c>

# Tell PHP that the mod_rewrite module is ENABLED.
SetEnv HTTP_MOD_REWRITE On

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?q=$1

</IfModule>


and index.php

<?php
// Print the value of the "q" parameters so we can compare it in our test function below.
echo "Current URL: " . $_GET['q'] . "<br/>\n";

// Prevent infinite loops by checking if this request is done by our function
if ($_GET['q'] != 'test_mod_rewrite') {
if (is_mod_rewrite_enabled()) {
print "The apache module mod_rewrite is enabled.<br/>\n";
} else {
print "The apache module mod_rewrite is NOT enabled.<br/>\n";
}
}

/**
* Verifies if the mod_rewrite module is enabled by calling itself in
* a way that will trigger the mod_rewrite rules.
* This only works if you have an .htaccess file in the same folder
* and if the rule will redirect anything to ?q=$1
*
* @return boolean True if the module is enabled.
*/
function is_mod_rewrite_enabled() {

// here failed

$content = file_get_contents("http://" . $_SERVER['HTTP_HOST'] . "/test_mod_rewrite");

// here failed




if ($content == "Current URL: test_mod_rewrite<br/>\n") {
return TRUE;
} else {
return FALSE;
}
}

edbr
11-07-2013, 05:37 AM
got that , it was the path. Bloody script will not install though grrrr!!