Forum Moderators: phranque

Message Too Old, No Replies

Strange 404 issue

404 pages acting strangely

         

ranadeep

7:17 pm on Jan 20, 2009 (gmt 0)

10+ Year Member



I'm not good with .htaccess but have learnt to make do with whatever I could gather from different websites. Now I'm facing a strange issue. All my css, js etc. are inside a directory say images i.e.
images/style.css
images/something.js
which is in the root folder.

I have created a .htaccess with ErrorDocument 404 /404.php and a customized 404.php which are also in the root i.e. public_html.

Now if I type a wrong url as www.mydomain.com/wrong it's showing my 404 page. But if I add a slash after the url i.e. www.mydomain.com/wrong/ then the 404 page is coming up but without the css and js, and all the relative links are showing up under the subdirectory i.e. www.mydomain.com/wrong/about.php when it should be www.mydomain.com/about.php

Please help me to figure out what I'm missing.

g1smd

8:13 pm on Jan 20, 2009 (gmt 0)

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



If you address your CSS files using a URL like "stylesheet.css" in your links, then to work out where to get the file from, your browser will append that filename to the end of the last trailing slash of the URL of the page that the file is called from, and use that as the URL.

So, a call from "/somepage" will be addressed as "/" + filename.

A call from "/folder/somepage" will be addressed as "/folder/" + filename.

A call from "/folder/somepage/" will be addressed as "/folder/somepage/" + filename.

It is working exactly as coded and exactly as per the specs.

.

If you want it to work some other way, then you need to address your stylesheet using links that begin with a leading slash, like "/stylesheet.css" or perhaps "/css/styles.css" instead.

That way, the CSS location is specified "counting from the root of the site" and the URL of the page that it is being called from is totally irrelevant to the calculation.

jdMorgan

8:26 pm on Jan 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it isn't clear from looking at your address bar, the custom 404 error page is presented (and treated internally) as if it had the URL of the non-existent page. So as g1smd points out, server-relative or canonical links and object references must be used within the error page HTML itself, because you cannot predict what URL will be requested, and so cannot predict what relative path might be used to include images, external CSS and JavaScripts, or any other objects in the page.

Jim

ranadeep

4:55 am on Jan 21, 2009 (gmt 0)

10+ Year Member



Thanks to you both. That did solve the issue.