473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

404 issue: a CSS problem?

12
Hi all,

I've created a 404 page which seemed to be working well in most circumstances, for example:
http://www.p-s-i.org.uk/bad_page

However it was pointed out to be when the faux page appeared in a sub-folder, all CSS seemed to be lost. For example:
http://www.p-s-i.org.uk/links/bad_page

Does anyone have any ideas?

Thanks in advance,
Dave
PS - sorry for the validation errors!
Oct 15 '08 #1
14 1624
Atli
5,058 Expert 4TB
Hi.

You are using a relative link to load your CSS file.
Expand|Select|Wrap|Line Numbers
  1. <link href="css/css.css" .../>
As a result, when your browser tries to load this from:
www.p-s-i.org.uk/bad_page, it correctly loads the www.p-s-i.org.uk/css/css.css file.

But... when you request www.p-s-i.org.uk/links/bad_page, it tries to load www.p-s-i.org.uk/links/css/css.css which doesn't exist.

Try adding a single / in front of your link href. That should tell the browser that the url is absolute, so it should start look at the web-root, rather than relative to the current page.
Expand|Select|Wrap|Line Numbers
  1. <link href="/css/css.css" .../>
Oct 15 '08 #2
updw123
12
Good thinking, thanks Atli!

I don't suppose anyone knows much about DW to know whether they have a replace all function? Or whether it would be easier to actually create a css route for each subfolder?!

Thanks again,
Dave
Oct 16 '08 #3
Atli
5,058 Expert 4TB
If you change the link in all of your files to the absolute URL I posted they would all load the same CSS file, no matter where they are in the file structure.

In Dreamweaver, you can do "Edit->Find and Replace", change the "Find in" dropdown to "Folder", select the root folder for your web, put the old link on "Find", your new link in "Replace", and do "Replace all"... that should take care of all the links.
Oct 16 '08 #4
updw123
12
Thanks Atli.

I'm not sure if it's something I'm doing wrong but I gave that a go and it didn't seem to make any difference.

Speak soon,
Dave
Oct 19 '08 #5
Markus
6,050 Expert 4TB
So prepending a forward slash tells the browser to start from the web root?
Oct 19 '08 #6
Atli
5,058 Expert 4TB
Yes. A link starting with a forward slash is treated as an absolute URL, just like you had written http://example.com/ in front of it. (Assuming your page is located at example.com, obviously).
Oct 19 '08 #7
Atli
5,058 Expert 4TB
Thanks Atli.

I'm not sure if it's something I'm doing wrong but I gave that a go and it didn't seem to make any difference.

Speak soon,
Dave
What exactly did you do?
Can you show us an example?

I tried applying the solution to your pages using Opera's handy source modifying thing and it seemed to work.

I tried a few invalid URL's, like http://www.p-s-i.org.uk/links/bad_page, and simply replaced this:
Expand|Select|Wrap|Line Numbers
  1. <link href="css/css.css" rel="stylesheet" type="text/css" />
with this:
Expand|Select|Wrap|Line Numbers
  1. <link href="/css/css.css" rel="stylesheet" type="text/css" />
and the CSS loaded just fine every time.
Oct 19 '08 #8
updw123
12
Hi Atli,

This isn't something I've come across before.

I applied the change to all pages. So for example if you visit any page, the / is present in the code, for example:
http://p-s-i.org.uk/education/universities.html

But when you type in a non-existent URL the / is not present, e.g.:
http://p-s-i.org.uk/education/bad_page

I'm really not sure what to do on that..

Speak soon,
Dave
Oct 19 '08 #9
Atli
5,058 Expert 4TB
There must be a page somewhere that loads instead of the typical 404 error, when a user tries to access a page that doesn't exist.

You need to find that page and change this there.

If you are using Apache, you can find this by going into the configuration file (or the .htaccess file in your web-root) and find the "ErrorDocument 404" directive. That should point you to the correct file.
Oct 19 '08 #10
updw123
12
Thanks Atli. I don't know how it got missed from the find all.

Although now it works, it won't display any images. The struggle goes on!
Oct 19 '08 #11
eWish
971 Expert 512MB
My suggestion would be to make the image files and links all absolute on the error page. Then you should not have any problems.

Change:
Expand|Select|Wrap|Line Numbers
  1. <img src='banner.jpg' alt='some alt text' />
To:
Expand|Select|Wrap|Line Numbers
  1. <img src='http://p-s-i.org.uk/banner.jpg' alt='some text' />
I would also do the same thing with the links to other pages. This might seem like a headache now but will be a lifesaver when someone enters a url like http://p-s-i.org.uk/some_dir/another...ir/another_dir. The links will not be found and it will be a big circle.

--Kevin
Oct 19 '08 #12
updw123
12
Looks good, thanks Kevin.
Oct 20 '08 #13
Atli
5,058 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. <img src='http://p-s-i.org.uk/banner.jpg' alt='some text' />
I wouldn't add the "http//p-s-i.org.uk" part tho.

Like I suggested before, if you simply prefix a forward slash to the link, your browser should interpret that as an absolute URL as well.
That also makes you web more portable, because you will not have to go through all your code and change every link if this is every to be used on another domain.

This would be equivalent to the <img> tag you posted:
Expand|Select|Wrap|Line Numbers
  1. <img src='/banner.jpg' alt='some text' />
Oct 20 '08 #14
eWish
971 Expert 512MB
My suggestion was meant to be for the error pages only. That way you are assured it works regardless of what the user enters.

--Kevin
Oct 20 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
2
by: MWells | last post by:
I've encountered an interesting issue regarding Url encoding that I'm hopeful someone can shed some light on. I have some vanity Url's that have to contain filename content, using the file...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
17
by: 57R4N63R | last post by:
I'm currently building a website for one of the client. There has been few errors here and there, but just recently the problem is getting worse. Basically the symptoms is that when the user try...
0
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". ...
5
by: Tom Anderson | last post by:
I am currently having an issue with an ASP.Net 1.1 Web page that does the following remotely but not locally. Click on a control Check for postback, if postback, handle the event, otherwise...
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
14
by: n3o | last post by:
Hello Comp.Lang.C Members, I have an issue with user input that I have been trying to figure out for the longest. For instance, let's say you have something like this: void foo() { int num;...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.