Forums / General Questions / getting a 302 response header for non-existent urls and a redirect to the Home Page?

getting a 302 response header for non-existent urls and a redirect to the Home Page?

Started by piker on 11 Oct 2013, 9:56 PM · Views: 5,596

Results 1 to 13 of 13
11 Oct 2013, 9:56 PM
#1
piker avatar

piker

Zen Follower

Join Date:
Nov 2009
Posts:
109
Plugin Contributions:
0

getting a 302 response header for non-existent urls and a redirect to the Home Page?

I'm thinking I may have changed a setting somewhere because shouldn't I be getting a page redirect to the Home Page with a 404 Header at the very least? This isn't great for my SEO indexing so I would really appreciate any advice on where to start tracking this down. I'm using Ceon Uri Rewrites, but that seems to be working as it should..
Cheers.

11 Oct 2013, 11:45 PM
#2
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

What happens when you temporarily turn off the URL rewrites ?

12 Oct 2013, 12:00 AM
#3
piker avatar

piker

Zen Follower

Join Date:
Nov 2009
Posts:
109
Plugin Contributions:
0

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

stevesh:

What happens when you temporarily turn off the URL rewrites ?
I have tried that in the config settings only (no change), but should I also comment out the rewrite rules in the htaccess at the same time?

12 Oct 2013, 12:54 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

Ya, without turning off the plugin and removing the rewrite rules, it's really hard to ascertain whether your problems are a result of the plugin or not.

Plus, a list of problematic URLs would be useful too. Leave off the http:// and any www. when posting them here unless you want them to get reindexed!

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Oct 2013, 2:39 AM
#5
piker avatar

piker

Zen Follower

Join Date:
Nov 2009
Posts:
109
Plugin Contributions:
0

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

Ok, when I comment out the rewrites and turn off the rewrite mod I get this:
allnatives.com.au/foo (gets a 404 as it should, instead of a 302)

But strangely I also get a 403 for these (which I don't get when I have the mod working):
allnatives.com.au/images/index.php?main_page=page_not_found
allnatives.com.au/includes/templates/forest_path/css/images/index.php?main_page=page_not_found
*if the mod is on and working I get a 302 for these.

Here is my .htaccess details:

#without these I get a 404 AND a Error Document not found error as well, when the mod is off
ErrorDocument 404 /
ErrorDocument 403 /

RewriteEngine on

CEON URI REWRITES

Don't rewrite any URIs ending with a file extension (ending with .[xxxxx])

RewriteCond $1 !.[a-zA-Z]{2,5}$ [NC]

Don't rewrite admin directory,editors,cpanel or frontend directories

RewriteCond $1 !^(admin|editors|cpanel|frontend) [NC]

Handle all other URIs using Zen Cart (index.php)

RewriteRule ^(.*)$ index.php [L]

12 Oct 2013, 2:53 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

piker:

Ok, when I comment out the rewrites and turn off the rewrite mod I get this:
allnatives.com.au/foo (gets a 404 as it should, instead of a 302)Okay. That's to be expected. The mod would do a 302 because of your rewrite rules.
If you want it to give a 404, you'll need to do some work writing more complex rewrite rules.

piker:

But strangely I also get a 403 for these (which I don't get when I have the mod working):
allnatives.com.au/images/index.php?main_page=page_not_found
allnatives.com.au/includes/templates/forest_path/css/images/index.php?main_page=page_not_foundThat's because of the security protections set in the .htaccess in /images/ and /includes/ to specifically prevent access to .php files, to prevent malicious exploits. So, that's the correct behavior.

piker:

*if the mod is on and working I get a 302 for these.That's fine too, since it still prevents unauthorized access.

piker:

#without these I get a 404 AND a Error Document not found error as wellThat's to be expected, since a 404 is a "Document not found" (aka "Page not found") error.

This all raises a deeper more important question: where are all these invalid hits coming from? If they're from search engine spiders then go clean up the pages where the links were gleaned else they'll just keep coming back no matter what header response is issued.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Oct 2013, 3:11 AM
#7
piker avatar

piker

Zen Follower

Join Date:
Nov 2009
Posts:
109
Plugin Contributions:
0

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

Thanks.
Foo was just an example, there aren't any in particular that i'm trying to fix I just expected to see a 404 and not a 302 for non-existent urls. The Google "problem" (only recently it seems..) is that these 302's back to my Home Page are seen as "soft 404s" and they don't like them much. I don't mind having a crack at a more complicated rewrite rule if anyone has an example?
Cheers.

12 Oct 2013, 4:49 AM
#8
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

piker:

I'm thinking I may have changed a setting somewhere because shouldn't I be getting a page redirect to the Home Page with a 404 Header at the very least? ...
There is a Zen Cart setting for how to handle when a page is not found. The options are to redirect to the home page, issue 404 but still show content, or send to a dedicated 404 page. Might want to check this setting.

"Configuration" -> "My Store" -> "Missing Page Check". If this is set to "on" you are redirected to the home page... I typically use the "Page not Found" option and modify the 404 Page built into Zen Cart to fit the store's needs. Using the "Page not Found" option plays well with most of the modules for generating alternative URLs including CEON URI Mapping.

As previously mentioned, if you see 404s in Webmaster tools, probably best long term to fix the links pointing to old / invalid URLs. But hopefully the above info helps as well!

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

12 Oct 2013, 5:21 AM
#9
piker avatar

piker

Zen Follower

Join Date:
Nov 2009
Posts:
109
Plugin Contributions:
0

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

"..probably best long term to fix the links pointing to old / invalid URLs.."
The main reason i'm seeing invalid links appearing in GWT all of a sudden (10-15 more a day!) is that a lot of my image files, which I don't mind being indexed, have a name like "foo bar.jpg" (I know I probably should have left that space out!) which are usually encoded for links as "foo%20bar.jpg", but there are some (and i'm suspecting Social Networking sites here) are encoding the link as "foo%2520bar.jpg". People click these and they get a 302 redirect to my Home Page, hence continual "404 soft errors". I think the best option (please correct me if i'm wrong) would be to rename all my images in the style "foo-bar.jpg" and do a 301 redirect to them. Sound good?
Thanks as well for your help, much appreciated.

12 Oct 2013, 6:21 AM
#10
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

sounds easier than dealing with extra rewrite rules to undo the double urlencode you are seeing (another option)... Out of curiousity, is this a specific social media API or network? Just in case anyone else runs into something similiar?

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

12 Oct 2013, 6:37 AM
#11
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

Sounds like a good long term plan. You may also want to set up some rewrite rules to 301 the old image URLs to the new ones if the images rank well in SEs...

Not in front of my computer at the moment to test, but the rule would probably look something like (may need some modification):

RewriteRule ^(.+?)%2520([^.].(?:jpe?g|png))$ $1%20$2 [R=301,L]

Replace the last %20 with - once the images have been renamed.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

12 Oct 2013, 9:35 AM
#12
piker avatar

piker

Zen Follower

Join Date:
Nov 2009
Posts:
109
Plugin Contributions:
0

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

Ive changed one of my image names to dashes (eg /images/foo-foo-foo.jpg) and am trying to formulate a rewrite that will cover one or more instances of either '%2520' and/or '%20', case insensitive and always a 'jpg' or 'JPG'. So far i've gotten a 500 error so i'm getting close :P

13 Oct 2013, 10:41 PM
#13
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Re: getting a 302 response header for non-existent urls and a redirect to the Home Page?

Alright, had a few moments to write up a proper regexp for mod_rewrite. This example will match requests with an instance of " ", "%20", or "%2520" and reply with a 301 redirect replacing the matched character(s) with a single "-" (will be applied as many times as the URL contains matches). This should be placed AFTER any hostname redirects (not really needed with Zen Cart but lots of people add these anyhow) and BEFORE any rules for handling "virtual" requests (requests where no physical file / folder exists).

RewriteRule ^(.+?)(?:(?:\ )|(?:%20))([^.]+\.(?:jpe?g|png))$ /$1-$2 [NC,R=301,L]

Note 1: Tested on Apache 2.4. Keep in mind this is just an example to show how to do this with a single instance of the matching space or %2520. Using the above code will cause one redirect for each matching %20 or %2520 (so if this string appears three times in the URL the customer will see 3 redirects). This can be avoided by crafting a regexp matching: first 5 instances, then 4 instances, than 3 instances, then one instance.

Note 2: The actual question asked is "Why am I getting a 302 response for non-existent URLs to the home page?". The answer has already been given. To change this behavior change the Zen Cart setting for handling missing pages.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker