Jump to content

Making 301 redirects work in the htaccess file

Recommended Posts

I've read a few posts about this topic but not one clearly seems to document how to make 301 redirects work with the Cubecart SEO code in the htaccess file. I've tried the simple written line redirect 301 and I've tried adding 301 redirects via my cpanel but none of them redirect to anything other than the cubecart error 404 page.

This is a fairly crucial requirement of any new site to be able to redirect removed or modified URLs yet it seems impossible to make it function within the cubecart htaccess file and there appears to be no documentation on how to make this work.

Any pointers to how to make this function normally much appreciated.

Link to post
Share on other sites

Are you working with CC641 or later? This version added a Redirects system for the internal management of friendly URL redirects. Being internal, making edits to the .htaccess file or via other mechanisms (Cpanel?) are no longer necessary.

In admin, in the navigation section ADVANCED is "Redirects". Here, the admin can manually enter the obsolete, no longer valid, friendly Path (probably not to include the trailing .html), Destination will be filled in after adding, Page, ID, and Code refers to the current object that had the obsolete path.

After adding this Redirect, it will show on the object's (such as Product) Search Engines tab.

Also, on that Search Engines tab, changing the existing friendly path to something new will, after saving, have added the old path to the Redirects system.

Link to post
Share on other sites

I've recently upgraded to 6.4.2 and I have seen the Advanced Redirects section where there are some strange entries that have appeared after installing a demo of the Enhanced Manufacturers plugin (see screen grab). which do not have a destination showing, however I couldn't work out how this advance section is used to manually enter a redirect for example:
to mydomain.co.uk/lighting-and-lamps

As there is no box to manually enter anything under the destination

BTW I think the screen grab is something I need to speak with the developer about in a separate topic.


Screenshot_2020-12-05 Admin Control Panel.png

Edited by onebrowncow
Link to post
Share on other sites

Destination will be filled in after clicking the Add button - the value in the Destination column is the current friendly path for the item type (product, document, etc) and item ID (if appropriate).

Also, when filling out the line of information, if you manually type in the Item ID of the product, category, or document, the Destination column will auto-populate with the currently defined friendly URL. One can also use the up/down cursor control keys to increment/decrement the value in the ID column which will fetch the currently defined friendly URL.

Also, as it is now, using the spinner buttons to select the Item ID value does not trigger the auto-population of the Destination column.

Those categories are strange.


Edited by bsmither
Link to post
Share on other sites

ok, so if I understand correctly, using the example I mentioned above, I would enter locomocean/brand_267.html (without a / at the front) in to the path box then select a category, product etc from the drop down page menu and then enter the new ID for the chosen destination in the item ID box, in this instance for my category lighting-and-lamps the unique category ID 295 would be entered and then I click add which will generate the new destination URL and create a 301 redirect.

(On a sub note, I think the strange redirects in the attached picture have been caused by me using identical names for my categories and brands which has thrown up a possible issue with the mod I mentioned).

Link to post
Share on other sites

You would enter locomocean/brand_267 as the Path you are not currently using, but perhaps had used it in the past and now want visitors who come to your site using that path to be redirected. Select Category, and enter 295 in the Item ID box.

After having entered 295 (not using the spinner), the Destination column should auto-populate with "lighting-and-lamps". Now click Add.

From this point on, visitors to www.store.com/locomocean/brand_267.html will get 301 redirected to www.store.com/lighting-and-lamps.html. (Using .html is a store setting option.)

Again, "locomocean/brand_267" is not currently in the CubeCart_seo_urls database table because nothing uses it. And, "lighting-and-lamps" is currently in the CubeCart_seo_urls database table because something is using it.

Link to post
Share on other sites

I have most of the redirects working but just cannot get anything containing cat in the url to redirect properly.
For example: I want to redirect the no longer used category mydomain.co.uk/jewellery/designer-jewellery/cat_203.html to mydomain.co.uk/jewellery (new id 391) so I enter designer-jewellery/cat_203.html in the path, select category from the spinner and 391 in the ID which correctly fills in the destination as jewellery however when you visit the url on a browser it returns an error message this category does not exist and a 404 message.

Category 391 Jewellery does exist and this occurs with ANY url containing an old, no longer used, category ID in the url that I try to redirect.

How do you make the redirects tool in advanced redirect a no longer used, obsolete, category correctly without returning the category not found and 404 error?

Link to post
Share on other sites

To me, it is a bit confusing as I haven't mapped out a set of rules. The rule map would show when and where including .html would be necessary, or optional, or unwanted.

So, to experiment, in Store Settings, Search Engines tab, note the setting for "SEO URL Extension". If the choice is None, then do not include .html in designer-jewellery/cat_203.html.

Link to post
Share on other sites

in Store Settings, Search Engines tab, note the setting for "SEO URL Extension". If the choice is None, then do not include .html

The result is the same regardless of including or not including the .html in the path which is odd as if the URL ends brand_xxx.html with SEO URL Extension set to None the redirect works, it only seems to not work if the url ends with _catxxx or _catxxx.html

Link to post
Share on other sites
2 minutes ago, bsmither said:

What is the difference between 'brand_xxx.html' and '_catxxx.html'?


proper examples are probably better

this URLwhich is also an old URL from my old CC4 will redirect without issue: locomocean/brand_267.html   and is an obsolete path to a brand URL

this URL which is also an old URL from my old CC4 is also obsolete and will NOT redirect regardless of what I enter in the path or target as the destination: handbags-and-accessories/poppy-treffry/cat_269.html

The only thing that seems to prevent the cat_269.html from redirecting is the inclusion of cat in the URL

Link to post
Share on other sites

Let's look at .htaccess:

  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(.*)$ index.php?_a=category&cat_id=$1&%1 [NC]

Here we see that CubeCart is using rewrite rules to preemptively catch CC4 URLs and make them CubeCart "standard" URLs. ("Standard" URLs - for CC5/6 - are not the same as the rigorously enforced "SEO-Friendly" URLs - for CC6.)

It is thus that CubeCart will be looking in the database for item type ('cat') and item ID ('269'), and (unfortunately) a redirect of zero. As regards CC4, the 'friendly' portion of the URL does not matter.

So, there is a choice of letting .htaccess do its thing, and when CubeCart issues a redirect with category 269's obsolete, but recorded SEO-friendly URL ('handbags-and-accessories/poppy-treffry') set with a 301 bounce, will eventually get to the current SEO-friendly URL (whatever that may be).

Or, load up the Redirects system with all your CC4 URLs (again, probably not using .html) and edit the .htaccess file removing all the CC4 backward compatibility rewrite rules.

The brand thing is a CC4 add-on not affected by the compatibility rules in .htaccess.

Link to post
Share on other sites

Thanks for looking at this bsmither. I've decided not to start messing around with the htaccess file as the site is live and selling so i don't want to mess something up just for the sake of some old URLs that Google still wants to index. I'll just wait until Google gets bored with them and they vanish in to the depths of the net.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...