How to set up to show homepage instead of "404 page not found" error page?

Discussion in 'PHP' started by stinker, May 24, 2010.

  1. #1
    Hello everybody,

    Im advertising site in ad network and when ad is clicked from that site, it opens new window where supposed my site to appear, but it shows in address bar something like www.mysite.com/?adclickid=266sda4fs6ad4f and in a window shows
    "404 Page Not Found
    The page you requested was not found.
    "

    Please, if you can, answer those questions, you would help me a lot.
    1. Is there any way i can adjust in htacessor somewhere else in my host that it show homepage at least on error pages.

    2. Is this problem in my host set up or it is ad network problem?

    Thanks a lot!
     
    stinker, May 24, 2010 IP
  2. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In reverse order:

    2. i guess you just missed setting up your configuration at the ads provider. If you see "www.mysite.com" at your browser bar and that isnt your site then you should consider chaging this "default value" to the address of your site.

    1. at .htaccess simply set up an Errordocument

    ErrorDocument 404 /shownonerror.html

    this would also work with "/anyscript.php" or just the site root "/" or the index "/index.html"

    Examples:

    ErrorDocument 404 /anyscript.php
    ErrorDocument 404 /
    ErrorDocument 404 /index.html
     
    flexdex, May 25, 2010 IP
    stinker likes this.
  3. stinker

    stinker Well-Known Member

    Messages:
    628
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thank you very much for fast response, Flaxdex,
    Im nearly green on programing, i've tried to add those commands to .htacccess, but nothing happens.
    I start to be suspicious on my htaccess file which i needed to setup in order wscript to work correctly.
    Here is what i have on my .htaccess:

    Options +FollowSymLinks
    RewriteEngine On
    #	leave just a normal / (slash) if the script is installed at root level otherwise enter it's folder here ex: /wscript (! no trailing slash)
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|install|scripts|fonts|uploads|robots\.txt|sitemap\.xml|favicon\.ico)
    
    #	if wscript is installed in a subfolder, add it before index.php ex: RewriteRule ^(.*)$ /wscript/index.php?/$1 [L] otherwise leave it as is
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    Code (markup):
    Wscript (wallpaperscript.net) has a lot of weird things i noticed (though it also very nice looking script at the same time).

    I would refer to their support too, but sadly, seems nowadays they have no support at all :(
     
    Last edited: May 25, 2010
    stinker, May 25, 2010 IP
  4. stinker

    stinker Well-Known Member

    Messages:
    628
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Update:
    As a test i deleted all this codes from .htaccess and added only ErrorDocument 404 /
    And it works, but when that code (posted in previous my post) is on .thaccess file, it doesn't work.
    Is it possible somehow to make it work together with all this texts?
    Thank you very much!
     
    stinker, May 25, 2010 IP
  5. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Its not .thaccess
    Its .htaccess

    Try this

     
    roopajyothi, May 25, 2010 IP
  6. stinker

    stinker Well-Known Member

    Messages:
    628
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Thanks for your help Roopajyothi,

    Just tried your suggested code, unfortunately it is the same error page :(
     
    stinker, May 25, 2010 IP
  7. vishalgaikar

    vishalgaikar Active Member

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #7
    Even I was looking for the same thread...thanks Roopa for your code
     
    vishalgaikar, May 25, 2010 IP
  8. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Stinker,

    you are about to route nearly everything to the script "index.php", thats what the "RewriteCond" and "RewriteRule" statements do. This is quite typical for a CMS.

    The script "index.php" does not know how to handle the request correctly and if the "ErrorDocument" statement points to the same script it will not work also.

    The question is, what do you want to do with that "addclickid"? Do you need it? Or can we trash it?

    In case you do not need that id you can simply add the following right after the "RewriteEngine On" statement and everything should be fine except the loss of that id.
    
    RewriteCond %{QUERY_STRING} ^adclickid=([\d\w]+)$
    RewriteRule ^.*$ /index.php [R=301,L]
    Code (markup):
    And everything with that "adclickid=blabla" will be rerouted without that id.

    Regards

    flex
     
    flexdex, May 25, 2010 IP