diff --git a/install.php b/install.php
index d07dfe6..63bb1fe 100644
--- a/install.php
+++ b/install.php
@@ -624,8 +624,6 @@ RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
TEXT
;
- $rewriteAlternative = $rewrite;
- str_replace("sapphire", $_SERVER['DOCUMENT_ROOT'] . '/sapphire', $rewriteAlternative);
$baseURL = dirname($_SERVER['SCRIPT_NAME']);
if($baseURL == "/") {
@@ -634,36 +632,92 @@ TEXT
if(file_exists('.htaccess')) {
$htaccess = file_get_contents('.htaccess');
- copy('.htaccess', '.htaccess_orig');
+
+ if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
+ $htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
+ }
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) {
- echo "
Existing .htaccess found, merging in SilverStripe rewrite rules";
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n";
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
}
}
- $this->createFile('.htaccess_rewrite', $start . $rewrite . $end);
- $this->createFile('.htaccess_alternative', $start . $rewriteAlternative . $end);
-
+ $this->createFile('.htaccess', $start . $rewrite . $end);
+ }
+ function createHtaccessAlternative() {
+ $start = "### SILVERSTRIPE START ###\n";
+ $end= "\n### SILVERSTRIPE END ###";
+ $rewrite = <<createFile('.htaccess', $start . $rewrite . $end);
+ }
+
+ function restoreHtaccess() {
+ $start = "### SILVERSTRIPE START ###\n";
+ $end= "\n### SILVERSTRIPE END ###";
+
+ if(file_exists('.htaccess')) {
+ $htaccess = file_get_contents('.htaccess');
+
+ if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
+ $htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
+ }
+
+ if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) {
+ $start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n";
+ $end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
+ }
+ }
+
+ $this->createFile('.htaccess', $start . $end);
}
function checkModRewrite() {
- copy('../.htaccess_rewrite', '../.htaccess');
if($this->performModRewriteTest() == true) {
return true;
}
- copy('../.htaccess_alternative', '../.htaccess');
+ $this->createHtaccessAlternative();
if($this->performModRewriteTest() == false) {
echo "ERROR: mod_rewrite not working, redirecting to mod_rewrite test page";
- if(file_exists('../.htaccess_orig')) {
- copy('../.htaccess_orig', '../.htaccess');
- } else {
- unlink('../.htaccess');
- }
+
+ $this->restoreHtaccess();
+
echo "I will now try and direct you to rewritetest to troubleshoot mod_rewrite
";
@@ -689,14 +743,14 @@ TEXT
// Workaround for 'URL file-access is disabled in the server configuration' using curl
if(function_exists('curl_init')) {
$ch = curl_init($location);
- $fp = @fopen("temp", "w");
+ $fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
- $testrewriting = file_get_contents('temp');
- unlink('temp');
+ $testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
+ unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
if($testrewriting == 'OK') {
return true;
}
diff --git a/rewritetest.php b/rewritetest.php
index 1e8ac75..f1d8f1a 100644
--- a/rewritetest.php
+++ b/rewritetest.php
@@ -1,8 +1,6 @@
setTimeout(function() { window.location.href = 'home/successfullyinstalled'; }, 1000);
";
} else {
- unlink('.htaccess');
- if(file_exists('.htaccess_orig')) {
- copy('.htaccess_orig', '.htaccess');
- }
+ restoreHtaccess();
+
echo "mod_rewrite doesn't appear to be working. Make sure:" .
"" .
"- mod_rewrite is enabled in your httpd.conf
" .
@@ -57,14 +53,14 @@ function performModRewriteTest() {
// Workaround for 'URL file-access is disabled in the server configuration' using curl
if(function_exists('curl_init')) {
$ch = curl_init($location);
- $fp = @fopen("temp", "w");
+ $fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
- $testrewriting = file_get_contents('temp');
- unlink('temp');
+ $testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
+ unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
if($testrewriting == 'OK') {
return true;
}
@@ -72,4 +68,113 @@ function performModRewriteTest() {
return false;
}
+
+function createHtaccess() {
+ $start = "### SILVERSTRIPE START ###\n";
+ $end= "\n### SILVERSTRIPE END ###";
+ $rewrite = <<