Make this type of 404 page

biscoolcool

New Member
Messages
53
Reaction score
0
Points
0
I know how to make a 404 page, and how to make it work. Heres my question: If I go on mywebsite.com/fakeurl it redirects me to mywebsite.com/404 page.
If you go to MS http://www.microsoft.com/fakeurl it doesn't redirect you. It puts fakeurl (your invalid request) in the search box.
How do I do this for my website? Do I need mod_rewrite?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
It probably does not 'redirect' you. Look at the URL in the address window next time your site throws a 404.

1. Create a file, call it 404.php (can name it anything, just easier to keep track of if you name it for the error). Should be a php file.
2. Make the page pretty, etc. You can access the URI (relative to document root ) by using

Code:
<?php echo $_SERVER[ 'REQUEST_URI' ] ?>

Example of full page...
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <title>Not here, I looked for it.</title>
	<style type="text/css">
		body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
		div.dialog {
			width: 25em;
			padding: 4em 4em;
			margin: 4em auto 0 auto;
			border: 2px solid #bbb;
			border-right-color: #777;
			border-bottom-color: #888;
		}
		h1 { font-size: 110%; color: #f00; line-height: 1.5em; }
		h2 { font-size: 90%; color: #000; line-height: 1.5em; }
		h3 { font-size: 80%; color: #333; line-height: 1.5em; }
		h4 { font-size: 70%; color: #666; line-height: 1.1em; }
	</style>
</head>
<body>
<div class='dialog'>
<h1>__________  404  __________</h1> 

<p>

<h2>Sorry, you must have dialed a wrong number</h3> 
<h3>The page you requested , <?php echo $_SERVER[ 'REQUEST_URI' ] ?> , cannot be found at this moment.</h3>
<h4>I looked for it. Honest. It's not there</h4>
</p>
 </div>

</body>
</html>

3. Add to .htaccess (I keep my custom error pages in a error/ subdirectory.)

Code:
ErrorDocument 404 /error/404.php
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
When the ErrorDocument directive is given a local URL path, it shouldn't redirect (see the ErrorDocument documentation for details). What are the configuration lines from your .htaccess that mention the error documents by URLs? For example, list all ErrorDocument and any applicable RewriteRule lines.
 

biscoolcool

New Member
Messages
53
Reaction score
0
Points
0
No I still get redirected. If I type in a random URL like http://bit.ly/TGP7t(please don't write the real url I don't want this page to get indexed) I still get redirected.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Are you using a CMS?

Could you post your .htaccess file?

(Just noticed that it redirects you from your .co.cc domain to your exofire.net )
 
Last edited:

like2program

New Member
Messages
244
Reaction score
0
Points
0
I must point out that this is very liable to be used for XSS the way you coded it, I would recommend that the input is sanitized before you directly output it to the page.

example "http://web.site.com/<script>XSS()</script>"
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I must point out that this is very liable to be used for XSS the way you coded it, I would recommend that the input is sanitized before you directly output it to the page.

example "http://web.site.com/<script>XSS()</script>"

Point taken.

Just as quick code examples for form input etc, I often do not include all the sanity checks. I hope the people reading the examples understand the problems with XSS, SQL injection, etc.

I do not use the above code for my error pages. I wanted to use $_SERVER[ 'REQUEST_URI' ] to show how you can access the original request in an error document.
 

pythondev

New Member
Messages
59
Reaction score
0
Points
0
for 404 put in a .htaccess folder in your httpdocs folder
an example below

Code:
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

ErrorDocument 404 /index.php?p=404
ErrorDocument 403 /index.php?p=403

doing this way you can build your page exactly how you want it.
other examples are:
ErrorDocument 404 /errors/404.php
ErrorDocument 404 /404.php
ErrorDocument 404 /errors.php?error=404

etc etc
 

biscoolcool

New Member
Messages
53
Reaction score
0
Points
0
I must point out that this is very liable to be used for XSS the way you coded it, I would recommend that the input is sanitized before you directly output it to the page.

example "http://web.site.com/<script>XSS()</script>"
Don't Understand a thing.
I don't use any CMS.
If we are starting with the .htaccess I have another question.
I kept on trying to find a code so that when a visitor types my website with www it transfers them to the non www page. I found them but none work.
I have 2 .htaccess files.
File 1) In the root
Code:
ErrorDocument 404 http://bit.ly/3ZpDr5/errordocs/404.php
NOTE: I don't want to write mu URL in text. The .htaccess files has the real name instead of the bit.ly one.
File 2) In public_html
Code:
#prevent viewing of .htaccess
<Files .htaccess>order allow,denydeny from all</Files>
# Redirect if NOT example.com (exactly) to example.com 

#switch php extentionAddType application/x-httpd-phpv2 .htm .html
#errorsErrorDocument 404 http://bit.ly/3ZpDr5/errordocs/404.php
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
As mentioned in a previous post and the linked documentation for ErrorDocument (there's a reason I wrote my sig; note the bits about reading links and answering questions), use a local URL path to keep from redirecting. By prefixing the error document URL with "http://bit.ly", you're causing a redirect.

If we are starting with the .htaccess I have another question.
I kept on trying to find a code so that when a visitor types my website with www it transfers them to the non www page. I found them but none work.

See the Apache URL Rewriting Guide, Canonical Hostnames section.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
3. Add to .htaccess

Code:
[B]ErrorDocument 404 /error/404.php[/B]

File 2) In public_html
Code:
[B]ErrorDocument 404 /error/404.php[/B]
[B]# ErrorDocument 404 404.php[/B]
[B]# ErrorDocument 404 404.html[/B]
[B]# ErrorDocument 404 missingpage.html[/B]

Add the line (depending on where you store the error page and how you name it)
and you will not be redirected.

Also, what do you mean by "File 1) In the root" ? Do you mean in /home/USERNAME ? You should probably change the line there too.
 

biscoolcool

New Member
Messages
53
Reaction score
0
Points
0
Also, what do you mean by "File 1) In the root" ? Do you mean in /home/USERNAME ? You should probably change the line there too.

Ok ill give it a try. Yes, it's in /home/username
Edit:
Now I get an internal server error (error 500)
I removed the .htaccess file in my root and changed the one in public_html

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, support@x10hosting.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Edit:
****EDIT****
Now I just a regular 404 error from my browser
 
Last edited:

playminigames

New Member
Messages
216
Reaction score
6
Points
0
ok, to get your url to go from examle.com to www.example.com you can insert this line of code into the .htaccess page(i use it so i know it works)

You need this part to so anything with mod_rewrite
Code:
Options +FollowSymlinks
RewriteEngine on

and this is the part that does the example.com->www.example.com
Code:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

all "." have to be backslashed in RewriteCond, good luck with this, it should work.

and for error pages

Code:
ErrorDocument 404 /error/404.php

explained: 404 shows what error this is for, and the /error/404.php is where the new 404 error page is, it is best to make a new directory, as you can make different ones like400 error ect.

I hope this works for you, as it did for me, if you need any more help dont be afraid to PM me.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
biscoolcoo said:
Now I just a regular 404 error from my browser

So it seems to be working now.

As pointed out above, you might want to use:

htmlentities( $_SERVER[ 'REQUEST_URI' ] )

to 'sanitize' the uri requested.
 

biscoolcool

New Member
Messages
53
Reaction score
0
Points
0
I didn't have
Code:
Options +FollowSymlinks
in my .htaccess file.
I'm still getting a 404 page from my browser if I type a random URL
If in .htaccess I put the full URL (with http) I get a error from my site but if I write just the path I get an 404 error from my browser.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I didn't have
Code:
Options +FollowSymlinks
in my .htaccess file.

Neither do I.

I'm still getting a 404 page from my browser if I type a random URL

Isn't that what you want?

If in .htaccess I put the full URL (with http) I get a error from my site but if I write just the path I get an 404 error from my browser.

Why are you putting full URLs in .htaccess?
 

biscoolcool

New Member
Messages
53
Reaction score
0
Points
0
I want to get an error on my site not a browser 404 error. If I type the full url in .htaccess I will get the error on my site but if I type the short url (with out the http) I get the 404 error from my browser.
I want the error from my site.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I click on the link you provided above.
It puts out a page that says:

The URL that you requested /biwet3479p534 wasn't found.

The URL in the address bar is the URL that was requested.
What is the problem?
 

biscoolcool

New Member
Messages
53
Reaction score
0
Points
0
I found out why this happens. I use Google Chrome as my default browser. I have the Google toolbar in IE, but not in Firefox. I get a browser 404 error from IE and Chrome, but I get my error in Firefox.
 

Mr. DOS

Member
Messages
230
Reaction score
5
Points
18
IE6 only displays a website-provided 404 page if it's longer than 512B and as-is, your error page is only 337B. This may be a wild goose chase, but what if IE7 and 8 and Chrome do the same as IE6? Try padding your HTML with a long enough comment to bring the page size over that minimum, or start prettying up the page with styling and whatnot (that should raise the size pretty quickly).

--- Mr. DOS
 
Top