Jump to content

404 not working


stl314
 Share

Recommended Posts

There are links out there on the web that link to my old store (I was using a hosted store and had my domain name attached to it)

Now that I have moved to cube cart and hosting my own store, when people click on those links they are coming to a page that is within my template that says:

404 - Page Not Found

Sorry but the page you are looking for could not be found.

 

 

Why is this not redirecting to my home page?

Link to comment
Share on other sites

Could you give an example of a url that 404's and what the url for your CC page should be? Also, what is in your .htaccess file now? There IS a 404 page coded in the Foundation template files. You are free to re-word it to suit yourself. It should show all the page structure found in main.php except for the Latest Products and possibly some plugin additions, plus your 404 wording.

Link to comment
Share on other sites

This page is a link that is constantly being used lately, but it is from my old store. When you click it, you will see that it just leads to a page saying page not found. I just want 404's to redirect to the home page

http://www.shirtactivism.com/index.aspx?pageid=1855718&amp%3Bprodid=9134693

 

Here is what is in my htaccess file

 

##### START CubeCart .htaccess #####

### File Security ###
<FilesMatch "\.(htaccess)$">
  Order Allow,Deny
  Deny from all
</FilesMatch>

### Apache directory listing rules ###
DirectoryIndex index.php index.htm index.html
IndexIgnore *

### Rewrite rules for SEO functionality ###
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase / 
  
  ##### START v4 SEO URL BACKWARD COMPATIBILITY #####
  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(.*)$ index.php?_a=category&cat_id=$1&%1 [NC]

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

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

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

  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule _saleItems(\.[a-z]+)?(\?.*)?$ index.php?_a=saleitems&%1 [NC,L]
  ##### END v4 SEO URL BACKWARD COMPATIBILITY #####

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)\.html?$ index.php?seo_path=$1 [L,QSA]
</IfModule>

### Default store 404 page ###
ErrorDocument 404 /index.php

## Override default 404 error document for missing page resources ##
<FilesMatch "\.(gif|jpe?g|png|ico|css|js|svg)$">
  ErrorDocument 404 "<html></html>
</FilesMatch>
##### END CubeCart .htaccess #####

 

 

 

Link to comment
Share on other sites

There are two aspects to look into:

.htaccess file: If the Rewrite Parser fails to match on the URL and rewrite it, then the web server will send the designated 404 page, which, if specified in .htaccess, is CubeCart's index.php.

CubeCart 1: However, because the web server has also set the HTTP Response Status to 404, the code in CubeCart can (and does) test for this. If 404, CubeCart assembles the standard storefront page and uses the 404 template for the main contents.

CubeCart 2: If the Rewrite Parser does match and the URL is rewritten, but the resultant SEO Path is not found in the database, then, CubeCart also displays the "404" contents.

At one time, I recall seeing an admin setting to show the 404 content or not. I'm not finding it now.

In your example above, the actual document being requested is index.aspx. That (probably) definitely does not exist.

 

Link to comment
Share on other sites

Let's try this promising solution. Edit the content.404.php template to say something more friendly, like:

"Welcome to my store! The link you used to find us is no longer valid. We invite you to browse the many quality products we have to offer. Click this <link> to view our Latest Products."

Or, with a small code edit, we can immediately bounce to the Latest Products, a certain Site Document, etc.

Or, we can try something new. What would you like to happen?

Link to comment
Share on other sites

Please try this:

In the file /classes/cubecart.class.php, line 59-61:

From:
		if (isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] >= 400) {
			$_GET['_a'] = '404';
		}

To:
		if (isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] >= 400) {
			http_response_code(301);header("Location: ".CC_STORE_URL);exit; $_GET['_a'] = '404';
		}

This now sets the response code to 301 (Permanent New URL, the browser should remember this and search engines will correct their indexes), then tells the browser to fetch the main page of your store.

We can also do something similar in .htaccess but by having CubeCart do it, we maintain the ability to use a hook to log the bad URLs for eventual attempts at locating the source.

 

Link to comment
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.

Guest
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.

 Share

×
×
  • Create New...