The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error Document - 404.shtml

Discussion in 'General Discussion' started by flashweb, Jun 2, 2004.

  1. flashweb

    flashweb Well-Known Member

    Joined:
    Mar 13, 2003
    Messages:
    243
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Hi,

    Cpanel uses 404.shtml as the default error document.

    How can i change 404.shtml to 404.php ?

    I need to use PHP as all my pages are in php, so i can use same site template for 404 pages too.

    Regards,

    Yujin
     
  2. AndyReed

    AndyReed Well-Known Member
    PartnerNOC

    Joined:
    May 29, 2004
    Messages:
    2,222
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Minneapolis, MN
    You can change 404.shtml to 404.php through httpd.conf
    SSH to your server, vi httpd.conf and change error pages extensions from .shtml to .php

    It should work.

    Andy Reed
    WebHostPad.com
     
  3. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    That would work, but it would result in a global change. Any other sites on the server would have to change their 404 pages. Also, any changes to the httpd.conf file will require restarting apache for the changes to take effect.
     
  4. AndyReed

    AndyReed Well-Known Member
    PartnerNOC

    Joined:
    May 29, 2004
    Messages:
    2,222
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Minneapolis, MN
    In this case the other option you might have is:
    ln -s 404.shtml 404.php

    Andy reed
    WebHostPad.com
     
  5. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    I just tested an idea and it worked. You can specify a different 404 page for 1 specific site by putting

    ErrorDocument 404 /whatever.ext

    inside the VirtualHost tags for that domain in the httpd.conf file.

    Just remember, always keep a backup of that file before modifying it, and after you make your change, you need to restart apache.
     
  6. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Could do that too.
     
  7. flashweb

    flashweb Well-Known Member

    Joined:
    Mar 13, 2003
    Messages:
    243
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    I need to change for few of my own sites.

    I can't do it for all web sites on the server as many other sites may be using 404.shtml as error page.
     
  8. SarcNBit

    SarcNBit Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    1,010
    Likes Received:
    3
    Trophy Points:
    38
    Have you tried creating an .htaccess file with;

    Code:
    ErrorDocument 404 [url]http://domain/404.php[/url]
    in it?
     
  9. flashweb

    flashweb Well-Known Member

    Joined:
    Mar 13, 2003
    Messages:
    243
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Thanks SarcNBit. Its working.
     
  10. SarcNBit

    SarcNBit Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    1,010
    Likes Received:
    3
    Trophy Points:
    38
    Your welcome. I had to ask, because sometimes the easy answer gets overlooked. ;)
     
  11. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    In my case it's because I haven't had the time yet to study the use of the .htaccess file so I don't fully understand how to use it. From what I've seen though, it appears that it can be used to do almost anything.

    The only things I do with .htaccess is whatever I've seen examples of. Some day I really need to take time to learn the workings of it.
     
  12. SarcNBit

    SarcNBit Well-Known Member

    Joined:
    Oct 14, 2003
    Messages:
    1,010
    Likes Received:
    3
    Trophy Points:
    38
    I hope your move went well.

    Substitute the word .htaccess in the above quote with the word cPanel (or 100 other things for that matter) and you pretty much sum up my knowledge base. ;)
     
  13. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Not yet. This weekend or next weekend I'm going to London, ON to stay at a motel for a week to look for a place for July 1. As of July 1, I'll be living in a bigger city with more potential for business. Still a tiny city compared to US ones, but one of the larger ones here in Canada.
     
  14. bamasbest

    bamasbest Well-Known Member

    Joined:
    Jan 10, 2004
    Messages:
    531
    Likes Received:
    0
    Trophy Points:
    16
    Larger than my Canadian favorite???

    Powell River, BC ;)!!!!
     
  15. X-Istencedotcom

    X-Istencedotcom Well-Known Member

    Joined:
    Apr 14, 2003
    Messages:
    223
    Likes Received:
    0
    Trophy Points:
    16
    .htaccess can be used for almost anything.

    You can use it to tell PHP to turn safe mode on or off, change limits for certain scripts, and other neat stuff.

    Code:
    #
    # Apache/PHP/site settings:
    #
    
    # Protect files and directories from prying eyes:
    <Files ~ "(\.(conf|inc|module|pl|sh|sql|theme)|Entries|Repositories|Root|scripts|updates)$">
      order deny,allow
      deny from all
    </Files>
    
    
    # Set some options
    Options Indexes FollowSymLinks
    
    # Customized server error messages:
    ErrorDocument 400 /error.php
    ErrorDocument 402 /error.php
    ErrorDocument 403 /error.php
    ErrorDocument 404 /error.php
    ErrorDocument 500 /error.php
    
    # Overload PHP variables:
    <IfModule mod_php4.c>
       php_value register_globals        0
       php_value track_vars              1
       php_value short_open_tag          1
       php_value magic_quotes_gpc        0
       php_value magic_quotes_runtime    0
       php_value magic_quotes_sybase     0
       php_value arg_separator.output    "&amp;"
       php_value session.cache_expire    200000
       php_value session.gc_maxlifetime  200000
       php_value session.cookie_lifetime 2000000
       php_value session.auto_start      0
       php_value session.save_handler    files
       php_value session.cache_limiter   none
       php_value allow_call_time_pass_reference  On
    #   php_value session.save_path         /home/personal/public_html/temp
    </IfModule>
    
    # Various rewrite rules
    <IfModule mod_rewrite.c>
      RewriteEngine on
    
      # Rewrite old-style URLS of the form 'node.php?id=x':
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{QUERY_STRING} ^id=([^&]+)$
      RewriteRule node.php index.php?q=node/view/%1 [L]
    
      # Rewrite old-style URLs of the form 'module.php?mod=x':
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
      RewriteRule module.php index.php?q=%1 [L]
    
      # Rewrite URLs of the form 'index.php?q=x':
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
    </IfModule>
    
    Is what i use on http://personal.x-istence.com/ with Drupal to allow for neat links, and so it can function properly.

    Blocking certain extensions and or directories is really nice as well, this way people do not get to go in and take a look at em.

    Code:
    RewriteEngine on
    
    
    # Lets not allow people to hotlink images. Its not very nice of them is it?
    
    # The sites we want to allow are the ones we list here, others are blocked.
    
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^[url]http://[/url](www\.)?x-istence.com(/)?.*$     [NC]
    RewriteCond %{HTTP_REFERER} !^[url]http://[/url](www\.)?download.x-istence.com(/)?.*$     [NC]
    RewriteCond %{HTTP_REFERER} !^[url]http://[/url](www\.)?personal.x-istence.com(/)?.*$     [NC]
    RewriteCond %{HTTP_REFERER} !^[url]http://[/url](www\.)?tutorials.x-istence.com(/)?.*$     [NC]
    RewriteCond %{HTTP_REFERER} !^[url]http://[/url](www\.)?forums.x-istence.com(/)?.*$     [NC]
    
    # This is our rewrite rules
    
    RewriteRule .*\.(gif|jpg|jpeg|bmp|png|wav|zip|mpg)$ - [F,NC]
    
    My Rewrite rules to stop people from other sites hotlinking my images. Works especially effective. Better than the standard cPanel ones i might add.
     
  16. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Thanks for the sample. This thread is bookmarked now.

    After I get moved and settled in, .htaccess will be one of the next things I do some serious studying on.
     
  17. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    I just looked it up on a map. Looks nice and big. ;)
     
Loading...

Share This Page