Admin
Moderating
Donor Member
Master Member
Elite Member
Active Member
- May 31, 2020
- 2,980
- 1,693
Magento 1.x no longer gets official security patches, so hardening your web server configuration is critical to reduce attack surfaces. You can implement rules for Apache or Nginx to block direct directory browsing, restrict file upload locations, and prevent direct access to PHP files outside of entry points.
Apache configuration (.htaccess):
After applying webserver rules, test site frontend, checkout and admin login to confirm no unintended 403 blocks.
Apache configuration (.htaccess):
- Disable directory listing for all foldersAdd this rule to your root .htaccess to stop visitors browsing your directories:
Options -Indexes
- Restrict file uploads only inside media folderBlock upload scripts and disallow file uploads outside /media. Prevent executable files from running inside media directory:
<FilesMatch "\.(php|phtml|php3|php4)$">
Require all denied
</FilesMatch>
<Directory "/media">
<FilesMatch "\.(php|phtml|php3|php4)$">
Require all denied
</FilesMatch>
</Directory>
- Block direct access to PHP files except index.phpPrevent accessing any standalone PHP files directly, only allow index.php as entry point:
Nginx server block rules:RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^.*\.php$ - [R=403,L]
- Disable directory listing
autoindex off;
- Deny direct access to PHP files except index.php
location ~* ^(?!/index\.php).*\.php$ {
return 403;
}
- Block PHP execution inside media folder
location ~* ^/media/.*\.php$ {
return 403;
}
- Restrict upload paths, block writable folders executionOnly /media should accept uploaded assets; block uploads in app, var, lib and other core directories.
Important notes:Always test these rules on staging first before applying to live sites. Incorrect webserver rules can break store frontend and admin access.These server rules are supplementary protection only. They cannot fully compensate for outdated core code. We recommend migrating your M1 to OpenMage LTS to receive community security fixes.Keep regular backups, restrict admin panel access by IP if possible, use strong admin passwords and avoid unknown third-party extensions.location ~ ^/(app|lib|var|includes|pkginfo)/ {
deny all;
}
After applying webserver rules, test site frontend, checkout and admin login to confirm no unintended 403 blocks.