Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

My custom 404 page is also giving 301 response

         

battlestar123

10:48 am on Aug 3, 2012 (gmt 0)

10+ Year Member



Hi, I created a custom 404 page with IIS 7.5 and MVC. My custom 404 page is working, but in addition to returning a 404 status code at the top, in Chrome, I am also seeing the 301 status being returned for several of the CSS and JS files I am including:

pagesnotfound GET 404 Not Found text/html
AlphaBanter.css GET 301 Moved Permanent text/html
...

This image snapshot gives a more detailed view of what I see in Chrome: [i.imgur.com ]

Please note the 301 statuses are being returned for the CSS and JS files after the top 404 status.

Will Google penalize my ranking because of the other 301 statuses being returned? Or will Google ignore the 301 statuses and only focus on the top 404 status being returned, and my page ranking will not be affected?

tedster

7:23 pm on Aug 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's the HTTP status of the html file that matters most. However, you should be able to link to the support files directly, with no redirects. For one thing, the page will load faster.

Is there something preventing a direct call rather than one to the redirected URL?

g1smd

7:34 pm on Aug 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are those other redirects from https to http or from non-www to www or something else?

lucy24

1:55 am on Aug 4, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



:: peering into crystal ball ::

Your Custom 404 directive says (allowing for translation from Apache into IIS)

ErrorDocument 404 www.example.com/my404.html

You say "in Chrome". Never mind about browser add-ons. What do you see in your logs?

battlestar123

7:18 am on Aug 4, 2012 (gmt 0)

10+ Year Member



>Are those other redirects from https to http or from non-www to www or
>something else?

I am testing on my localhost right now on my development computer (I have yet to upload this to my server) on IIS 7.5. Those redirects should be from http. Nothing on my site should be using https, that I know of.

Maybe this 301 is an issue when testing on localhost on a dev machine but will go away when I upload to my server?

battlestar123

7:24 am on Aug 4, 2012 (gmt 0)

10+ Year Member



>It's the HTTP status of the html file that matters most.

Thanks Tedster! It's good to know that Google will only take into account the status of the html file, and will ignore the status of the other CSS and JS files for page ranking.

>However, you
>should be able to link to the support files directly, with no
>redirects. For one thing, the page will load faster.
>
>Is there something preventing a direct call rather than one to the
>redirected URL?

Thanks Ted, you just gave me a hint. I added a some URLrewrite rules in IIS to rewrite all URLs to lowercase:

<rewrite>
<rules>
<rule name="RemoveTrailingSlashRule1" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Lower Case URLs" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="WebResource.axd" negate="true" />
</conditions>
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
</rules>
</rewrite>

I'm guessing that even the URL of CSS and JS files that are included are also rewritten to lowercase - that may be causing the 301 redirect. I have to head out now but I'll look into this when I get back.

tedster

9:16 am on Aug 4, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, you've got the IIS blues! I've had a bad "case" of those myself from time to time.

Whenever possible, I introduce the convention that all files and folders must be lowercase. It can be difficult getting the whole of a large web team to get on board, however. The redirect to lower case is a good thing, however the file itself should natively BE lowercase. There's no reason not to change .js or .css files to lowercase, even now.

battlestar123

1:12 pm on Aug 4, 2012 (gmt 0)

10+ Year Member



>Oh, you've got the IIS blues! I've had a bad "case" of those myself >from time to time.
>
>Whenever possible, I introduce the convention that all files and
>folders must be lowercase. It can be difficult getting the whole of
>a large web team to get on board, however. The redirect to lower
>case is a good thing, however the file itself should natively BE
>lowercase. There's no reason not to change .js or .css files to
>lowercase, even now.

Thanks to Ted and all of you for your help! The 301 redirect was caused by the URLRewrite rule to change all URLs - even URLs to CSS and JS files (JQuery javascript libraries included) - to lower case.

Once I removed the URLRewrite rule to Lower Case, I got proper 304 status codes for the CSS and JS files: [i.imgur.com ]

Curiously, the URLRewrite rule also causes a 301 redirect for the JQuery javascript libraries, even though the JQuery library names are already in lower case: [i.imgur.com ]. To have IIS not URLRewrite CSS files, JS files, etc, just add this line:

<add input="{URL}" pattern="^.*\.(axd|css|js|jpg|jpeg|png|gif)$" negate="true" ignoreCase="true" />

I found the above line at:
[umbraco.miketaylor.eu ]

g1smd

7:34 pm on Aug 4, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Curiously, the URLRewrite rule also causes a 301 redirect for the JQuery javascript libraries, even though the JQuery library names are already in lower case

What is the redirect from and to? It must be "correcting" something that was incorrect in the original request. If the redirect were to the exact same URL, there would be an infinite redirect loop.

Use the Live HTTP Headers extension for Firefox to see what is going on.

js|jpg|jpeg
simplifies to
j(s|pe?g)