| | 771 | * Try to copy htaccess-dist to .htaccess |
|---|
| | 772 | * @return bool |
|---|
| | 773 | */ |
|---|
| | 774 | function config_copy_htaccess() { |
|---|
| | 775 | $path = dirname(__FILE__) . '/'; |
|---|
| | 776 | $src = $path . 'htaccess-dist'; |
|---|
| | 777 | $dst = $path . '.htaccess'; |
|---|
| | 778 | $result = false; |
|---|
| | 779 | |
|---|
| | 780 | if (!file_exists($dst) && is_readable($src) && is_writable($path)) { |
|---|
| | 781 | $htaccess = file_get_contents($src); |
|---|
| | 782 | // Try to set RewriteBase |
|---|
| | 783 | include($path.'config.php'); |
|---|
| | 784 | if (!empty($CFG->wwwroot)) { |
|---|
| | 785 | $webpath = preg_replace("#^https?://[\w\.:-]+(/[\w-_\./]*)$#i", "$1", $CFG->wwwroot); |
|---|
| | 786 | if (!empty($webpath) && strpos($webpath, '://') === false && $webpath != '/') { |
|---|
| | 787 | $htaccess = preg_replace("|#RewriteBase /[^\w]|", "RewriteBase $webpath\n", $htaccess); |
|---|
| | 788 | } |
|---|
| | 789 | } |
|---|
| | 790 | |
|---|
| | 791 | $f = @fopen($dst, 'w'); |
|---|
| | 792 | if ($f) { |
|---|
| | 793 | @fwrite($f, $htaccess); |
|---|
| | 794 | @fclose($f); |
|---|
| | 795 | $result = true; |
|---|
| | 796 | } |
|---|
| | 797 | } |
|---|
| | 798 | |
|---|
| | 799 | return $result; |
|---|
| | 800 | } |
|---|
| | 801 | |
|---|
| | 802 | /** |
|---|