Skip to content

Instantly share code, notes, and snippets.

View joostvanveen's full-sized avatar

Joost van Veen joostvanveen

View GitHub Profile
@joostvanveen
joostvanveen / truncate_magento_log_tables.sql
Last active April 20, 2016 16:43
This query truncates alle cache, session, dataflow, index, log, report, quote, flat catalog, and URL rewrite tables. Handy, if you have a bloated Magento database and you need to do a bit of cleaning up for use on a local machine. USE AT OWN RISK. ALWAY BACKUP YOUR DATABASE FIRST.
--
-- This query truncates alle cache, session, dataflow,
-- index, log, report, quote, flat catalog, and URL
-- rewrite tables. Handy, if you have a bloated
-- Magento database and you need to do a bit
-- of cleaning up for use on a local machine.
--
-- Replace PREFIX_ with your current Magento table prefix.
--
-- USE AT OWN RISK. ALWAY BACKUP YOUR DATABASE FIRST.
@joostvanveen
joostvanveen / delete_products_and_categories_from_magento.sql
Created March 25, 2016 12:58
Delete all products and categories from Magento 1.9.2
-- Foreign key check will cascade-delete all related data
-- Delete all products
DELETE FROM catalog_product_entity;
-- Reset the autoincrement for products
ALTER TABLE catalog_product_entity AUTO_INCREMENT = 1;
-- Delete all categories
DELETE FROM catalog_category_entity WHERE `entity_id` > 2;
@joostvanveen
joostvanveen / remove_big_files-from_git_history.sh
Created March 17, 2016 17:24
Remove big files from git history to avoid error
# This command removes any sql.gz SQL backup file from history, even if it was committed a few commits ago.
# Handy for big files that throw an error when trying to push. As always, rewriting git history is a
# dangerous action! Do not rewrite for commits that have already been fetched by fellow developers.
git filter-branch --prune-empty -d /path/to/tmp/scratch/dir --index-filter "git rm --cached -f --ignore-unmatch *.sql.gz" --tag-name-filter cat -- --all
# purge varnish cache in Varnish 3
varnishadm "ban.url ."
# purge varnish cache in Varnish 4
varnishadm "ban req.url ~ /"
@joostvanveen
joostvanveen / get-magento-version-number.sh
Created January 25, 2016 14:47
Get Magento version number from command line
# Echo Magento version number
cd /path/to/magento/webroot
php -r "include 'app/Mage.php'; echo 'Magento version is: ', Mage::getVersion(); "
@joostvanveen
joostvanveen / .htaccess
Last active April 1, 2020 05:26
Force trailing slash for SEO purposes using htaccess 301 redirects (mod_rewrite) - but on GET requests only, to avoid losing POST data on a POST request to a URI without a trailing slash.
# Force trailing slash for SEO purposes
RewriteEngine On
# For GET and HEAD requests only. We do not want to redirect posted forms and such, or we'll lose all POST data!
RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
# Not for actual files. We do not want to redirect urls like test.jpg to test.jpg/
RewriteCond %{REQUEST_FILENAME} !-f
# Redirect to trailing slash if no slash is present in URI
@joostvanveen
joostvanveen / .gitignore
Last active April 10, 2019 08:54
Default gitignore entrances for IDEs, OS specific hidden files, tarballs and compressed files. Use this for new projects.
############ Project specific rules ###############
# Project specific rules go here...
# To ignore a folder, add asterix -> folder/*
# This way, unignored files like .keep and .gitkeep will still be added to git
################# Global rules ####################
## Never ignore .gitignore
!.gitignore
## Dependencies
@joostvanveen
joostvanveen / .htaccess
Last active September 10, 2023 02:37
.htaccess Security
######################################################################
## Word to the wise ##
## It is best to keep your htaccess files as clean as possible ##
## and set as many specs in your Apache config as you can. ##
## Htaccess slows down Apache. ##
## Review the entire file before use, especially the TODO sections. ##
######################################################################
Options -MultiViews
Options +FollowSymLinks
@joostvanveen
joostvanveen / .htaccess
Last active November 15, 2015 11:14
Canonical redirect in .htaccess - force www. prefix on domain
# Canonical redirect - force www. prefix on domain
RewriteCond %{HTTP_HOST} ^mydomain\.nl$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.nl/$1 [R=301,L]
@joostvanveen
joostvanveen / .htaccess
Last active April 22, 2021 20:12
Force SSL in .htaccess
# Force SSL, but only for a certain domain
# At the same time, redirect http non-www ad www to https://www
# Replace example\.com and example.com with your domain
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]