Create bulk 301 redirects with default Magento URL Rewrite Management to prevent 404 error. That’s the advice of Sander Lems, from ISM eCompany, shared in his presentation “Magento SEO Magento User Group” when moving from a old shop system to Magento. Instead of using .htaccess you can use the default Magento URL Rewrite Management. Implementation is not that hard. In this blogpost you will be explained how .csv files can be imported in Magento URL Rewrite table and prevent 404 error pages.
Create a single 301 redirect
When you want to prevent a single 404 error, a broken link to your website, the Magento URL Rewrite Management module is the place to be. It’s installed by default in every Magento installation. A 301 redirect informs Google and other search engines that the requested URL is permanent moved to another URL. Google and other search engines will adjust their index.
- Go to Catalog > URL Rewrite Management in your Magento admin panel
- Click “Add URL Rewrite” to add a new redirect
- Select “Custom” from field “Create URL Rewrite“
- Fill out the provided fields to complete the 301 redirect
- Store: only available if you have multiple store views
- ID path: unique ID for this rewrite. Since it’s a custom redirect I prefer using “custom/###”
- Request Path: the broken weblink
- Target Path: the new weblink
- Redirect: select “Permanent (301)”
- Done… test if the broken weblink will redirect to the new weblink.
This method is very easy when you want to create a single 301 redirect. It’s not so efficient when you have to create a lots of redirects.
Create bulk 301 redirects with database import
When you’re merging two websites or when you’re switching to Magento and you might have lots of outdated URLs. Instead of creating new URL rewrites one by one you can create them all at with a database import to the Magento URL Rewrite Management table.
- Provide your customer a spreadsheet with a list of all old weblinks and ask to complete the list with the new url structure. (Just two columns… “old URI” and “new URI”)
- Use the spreadsheet as input for the import. Copy the entire contents of the spreadsheet to an empty one and change / add some additional fields:
- change column name “OLD URI (should 301 redirect to new URI)” to “request_path” and remove leading slash “/”.
- change column name “NEW URI” to “target_path” and remove leading slash “/”.
- add column named “store_id”
- Type the Store ID in every line
- Open the store_view from “System > Manage stores” and get the “store_id” from the URL.
- add column named “id_path”
- Unique ID for this rewrite. Since it’s a custom redirect I prefer using “custom/###”
- Replace ### with numbers.
- Every line a new number
- add column named “options”
- Type “RP” in every line
- change the order of the columns to store_id,id_path,request_path,target_path,options
- Save spreadsheet as .CSV file with comma (,) as field delimiter and double quotes (“) as text delimiter.
- Open PHPmyAdmin and select the Database of your webshop
- Open table “core_url_rewrite” and go to tab “import”
- Browse your computer for the csv file to import.
- Select partial import and skip the first row with column names by starting the import from row 1 instead of 0.
- Column names: type in store_id,id_path,request_path,target_path,options
- table core_url_rewrites has more columns then present in our csv file. Therefor this entry is needed.
- Click button “GO” and let the magic happen
- Done… test if multiple broken weblinks will redirect to the new weblinks.
Create redirect using .htaccess
Creating redirects using Magento URL Rewrite Management is a preferred method instead of using .htaccess redirects. Redirect using .htaccess is possible too but not advisable. Try to prevent using .htaccess for redirects if you can use Magento URL Rewrite Management. Huge .htaccess files can slow down your website since it’s parsed during every request. The difference matters on high traffic website. Regular expressions on the other hand can redirect entire directories to new directories easily.
RewriteRule ^old_cat/(.*) http://example.com/$1/ [R=301, L]
It’s useful to read and apply the .htaccess performance tricks of blog post “Stupid htaccess Tricks” from PerishablePress.com.
as alway: have fun creating cool Magento webshops!
[widget id=”magereport_widget-5″ /]