5

I wish to create a series of rewrites so that the following redirect occurs:

Request: Category/ProductName.html
Target: category/productname.html

At present, visiting Category/ProductName.html renders a 404. When I try to create a URL rewrite to this, I get 'Request Path for Specified Store already exists.' and I think it's because of the casing.

Does anyone know a way around this?
These really need to be 301 redirects as they're from the old system, they're being transferred over to the new one and we can't have lots of 404s around the site because of a casing issue.

8

A huge amount of digging and I've found a single, tiny fix to get this to work.

Essentially, this is a drawback of MySQL as a data medium. MySQL is typically case insensitive. The field that stores the request paths has a 'UNIQUE' constraint upon it, meaning it can only store one of the below:

Category/ProductName.html
Category/productname.html

It treats both items the same, so the UNIQUE key disallows the second one, due to the presence of the first.

What I was able to do was change the COLLATION of the request_path field in the core_url_rewrite table from utf8 (the table default) to utf8_bin which makes it case sensitive.

4

Dan Hanly's approach is correct, but he failed to give the actual answer. Running this code in phpMyAdmin or other MySQL management utility will solve the issue:

ALTER TABLE core_url_rewrite MODIFY request_path VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin
1

I know that this is solved and unlikely still followed, but I had the same problem recently, and I have an alternative solution for those who may be hesitant to alter the database.

The lower-case value will get triggered when a camel-case version is requested, so the lower-case request_path will work for both circumstances. In your example, using a request path of 'Category/productname.html' will work for the exact-match as well as 'Category/ProductName.html,' or any other variation of case, e.g. 'CATEGORY/productNAMe.html.'

Because there is no altering the table-column, this also adds the advantage of being able to easily transfer to a new database, in the case that you are, for example, migrating from magento 1 to a new magento 2 instance.

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.