Browse Source

Fix auto detect base url for install

Visman 6 years ago
parent
commit
0251191136

+ 14 - 0
.dist.htaccess

@@ -0,0 +1,14 @@
+AddDefaultCharset UTF-8
+
+<IfModule mod_rewrite.c>
+  RewriteEngine On
+  #RewriteBase /
+
+  RewriteRule ^favicon\.ico$ public/favicon.ico [L]
+  RewriteRule ^robots\.txt$ public/robots.txt [L]
+
+  RewriteRule !^public/. index.php [L]
+
+  RewriteCond %{REQUEST_FILENAME} !-f
+  RewriteRule ^public/ index.php [L]
+</IfModule>

+ 4 - 0
.gitignore

@@ -1,6 +1,10 @@
 .old
+/.htaccess
+/index.php
 /app/config/main.php
 /app/config/_*
 /app/cache/**/*.php
 /app/cache/**/*.lock
 /public/img/avatars/*
+/public/.htaccess
+/public/index.php

+ 0 - 4
app/Controllers/Install.php

@@ -35,10 +35,6 @@ class Install
         }
         $uri = \rawurldecode($uri);
 
-        $this->c->BASE_URL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://'
-            . \preg_replace('%:(80|443)$%', '', $_SERVER['HTTP_HOST'])
-            . \substr($uri, 0, (int) \strrpos($uri, '/'));
-
         $this->c->Lang->load('common', $this->c->config->o_default_lang);
         $this->c->user = $this->c->users->create(['id' => 2, 'group_id' => $this->c->GROUP_ADMIN]);
 

+ 3 - 3
app/Models/Pages/Install.php

@@ -1180,10 +1180,10 @@ class Install extends Page
             '_DB_USERNAME_'   => $this->c->DB_USERNAME,
             '_DB_PASSWORD_'   => $this->c->DB_PASSWORD,
             '_DB_PREFIX_'     => $this->c->DB_PREFIX,
-            '_SALT_FOR_HMAC_' => $this->c->Secury->randomPass(mt_rand(20,30)),
+            '_SALT_FOR_HMAC_' => $this->c->Secury->randomPass(\mt_rand(20,30)),
             '_COOKIE_PREFIX_' => 'fork' . $this->c->Secury->randomHash(7) . '_',
-            '_COOKIE_KEY1_'   => $this->c->Secury->randomPass(mt_rand(20,30)),
-            '_COOKIE_KEY2_'   => $this->c->Secury->randomPass(mt_rand(20,30)),
+            '_COOKIE_KEY1_'   => $this->c->Secury->randomPass(\mt_rand(20,30)),
+            '_COOKIE_KEY2_'   => $this->c->Secury->randomPass(\mt_rand(20,30)),
         ];
         foreach ($repl as $key => $val) {
             $config = \str_replace($key, \addslashes($val), $config);

+ 10 - 1
app/config/install.php

@@ -4,8 +4,17 @@
 \ini_set('display_errors', 1);
 \ini_set('log_errors', 1);
 
+function forkGetBaseURL()
+{
+    $baseURL = 'http://'
+        . \preg_replace('%:(80|443)$%', '', $_SERVER['HTTP_HOST'])
+        . \str_replace('\\', '/', \dirname($_SERVER['SCRIPT_NAME']));
+
+    return \rtrim($baseURL, '/');
+}
+
 return [
-    'BASE_URL'         => 'http://forkbb.local',
+    'BASE_URL'         => forkGetBaseURL(),
     'DEBUG'            => 0,
     'GROUP_ADMIN'      => 1,
     'GROUP_MOD'        => 2,

+ 7 - 0
index.dist.php

@@ -0,0 +1,7 @@
+<?php
+
+$forkStart = empty($_SERVER['REQUEST_TIME_FLOAT']) ? \microtime(true) : $_SERVER['REQUEST_TIME_FLOAT'];
+$forkPublic = __DIR__ . '/public';
+$forkPublicPrefix = '/public';
+
+require __DIR__ . '/app/bootstrap.php';

+ 3 - 3
public/.htaccess → public/.dist.htaccess

@@ -3,9 +3,9 @@ AddDefaultCharset UTF-8
 <IfModule mod_rewrite.c>
   RewriteEngine On
   #RewriteBase /
+
   RewriteCond %{REQUEST_FILENAME} !-f
-  #RewriteCond %{REQUEST_FILENAME} !-d
-  #RewriteCond %{REQUEST_URI} !/public/.*\.\w+$
-  RewriteCond %{REQUEST_URI} !favicon\.ico
+  RewriteCond %{REQUEST_URI} !^/favicon\.ico$
+  RewriteCond %{REQUEST_URI} !^/robots\.txt$
   RewriteRule . index.php [L]
 </IfModule>

+ 0 - 0
public/index.php → public/index.dist.php