Truncate Magento 1.9 Core URL Rewrites

Truncate Magento 1.9 Core URL Rewrites

October 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Truncate Magento 1.9 Core URL Rewrites

Truncating Old Magento URL Rewrites

As a seasoned developer, I often encounter scenarios where we need to clean up our Magento databases, especially when dealing with the core_url_rewrite table that can quickly grow in size and complexity over time.

The Challenge: Removing Expired URL Rewrites

In your case, you’re looking to remove any URL rewrites that are older than 3 months. This is a common requirement when you want to optimize database performance or comply with data retention policies.

The core_url_rewrite table stores all the URL rewrites Magento generates for your products and categories. Over time, these entries can become outdated as you update your site’s structure or delete old products. If left unchecked, this can lead to a significant increase in database size.

The Solution: Using SQL Queries

To solve this issue, we can make use of MySQL queries to identify and remove the outdated URL rewrites. Here’s how:

DELETE FROM core_url_rewrite WHERE created_at < DATE_SUB(NOW(), INTERVAL 3 MONTH);

This query uses the created_at field in the core_url_rewrite table, which is automatically set by Magento when a new rewrite is created.

  • The DATE_SUB(NOW(), INTERVAL 3 MONTH) expression calculates the date exactly 3 months ago from the current date.
  • The < operator compares this date with each row’s created_at field.
  • If a row was created before this date, it gets deleted by the DELETE statement.

Best Practices for Safe Truncation

Before executing any delete queries on your live database, always remember to:

  1. Back up Your Database: Make sure you have a recent backup of your database before proceeding with any deletions. This is your safety net in case anything goes wrong.

  2. Test in Staging: Before running the query on your production site, test it first in a staging environment that mirrors your live setup as closely as possible.

  3. Monitor Your Database Size: After running the query, monitor your database size to ensure the deletion was successful and did not cause any unexpected side effects.

Conclusion

Truncating old URL rewrites is an essential part of maintaining optimal performance for your Magento store. By using the SQL query I provided, you can effectively remove entries that are older than 3 months with minimal impact on your site’s functionality.

Remember, while this query targets only outdated rewrites based on their creation date, it does not take into account any potential dependencies between rewrites and other parts of your system. Always ensure that the data being deleted is safe to remove before proceeding.

If you’re looking for more advanced techniques in Magento database management or need assistance with other aspects of e-commerce development, feel free to visit Laravel Company for expert advice and solutions tailored to your needs.

Magento 1 Catalog Database Performance

Our network