Forum Moderators: DixonJones

Message Too Old, No Replies

High Hits on 302 Redirect

         

digic

5:10 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



I almost have 39,000+ hits or 87.5% on 302 Moved Temporarily Redirect.

What is confusing is that I have old redirect on htaccess and they are not my top articles based on logs. Awstats is what I am using.

What could it be causing this 302's? Aside from htaccess, just in case I was hacked, are there any place where I can view the causes?

jdMorgan

5:34 pm on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be sure that your .htaccess code is specifying a 301 redirect for intentional redirects, and not a 302.

Also, check for the number-one cause of unintentional 302 redirects on Apache -- incorrectly-coded ErrorDocument directives:

Incorrect:
ErrorDocument 404 http://www.example.com/error-404.html

Correct:
ErrorDocument 404 /error-404.html

Including a full URL in an ErrorDocument directive forces a 302 redirect, and the requesting client will not see the correct server status response code -- it will see a 302-Found. This behaviour is clearly documented in the Apache core documentation.

The Live HTTP Headers add-on for Firefox and other Mozilla-based browsers is a good tool to thoroughly check your server response codes.

Jim

digic

2:25 am on Jul 10, 2009 (gmt 0)

10+ Year Member



Hi Jim, thanks for the reply, here are some contents of my htaccess file. Can you spot incorrect entry?

AddHandler application/x-httpd-php5 .html
AddHandler application/x-httpd-php5 .htm

<Files 403.shtml>
order allow,deny
allow from all
</Files>

# Redirect /index.htm [mydomain.com...]

RedirectMatch permanent ^/blogs/2006/11/15/webpage/$ [mydomain.com...]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^subdirectory/webpage1.htm$ "http\:\/\/www\.mydomain\.com\/blogs\/2008\/01\/01\/webpage1\/" [R=301,L]

I have at least 10 "RedirectMatch permanent" and a couple of "RewriteRule"

Thanks

jdMorgan

2:52 am on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suggest that you use the RewriteRule directive for all redirects, since you have used it for some. This allows you to control the order and priority of redirects.

Understand that "Redirect/RedirectMatch" and "RewriteRule" are interpreted by two different Apache modules, mod_alias and mod_rewrite. The order in which those two modules execute is variable, and is determined by the server configuration. Each module scans your .htaccess file and executes the directives that it understands. Therefore your directives are not executed in strict top-to-bottom order, they are executed in per-module order.

However, if you choose to continue to use "Redirect" and "RedirectMatch", then specify either "301" or "Permanent" after the directive, as in

 Redirect 301 ^/index\.htm http:/example.com/ 

If you do not specify "301" or "Permanent" then the redirect is a 302 by default.

BTW, there is no need for the RewriteCond on the RewriteRule you posted above, because as coded, it doesn't actually do anything at all.

Jim