[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 581
  • Last Modified:

Zeus Web Server 404 redirects

I'm hosting a web site on a Zeus Web Server (not my choice!). I have a custom error page to handle 404 redirects. This is done via an entry in .htaccess:

ErrorDocument 404 ./error.php

My problem is that the php variable $_SERVER['REQUEST_URI'] does not return the offending url (which caused the 404).

I'm wondering how can I access the offending URL within the PHP error page?

Many thanks for any help!
0
amrshalaby
Asked:
amrshalaby
  • 5
  • 4
1 Solution
 
Ray PaseurCommented:
Here is how I do it on my server.  Not sure Zeus will be your friend, but this works for me.  You can see it in action here (note the missing PHP suffix).
www.landonbaseball.com/player?key=3

In .htaccess:
ErrorDocument 404 /404handler.php

Of course, if Zeus is not populating $_SERVER correctly, you may be out of luck.  One way to see what is in there is to put up a phpinfo() script in place of the 404 handler, and go to a missing URL with a request string like foo?key=bar.  You will get to see everything that Zeus has given you.

HTH, ~Ray
<?php // 404handler.php
error_reporting(E_ALL);
session_start();

// IF THERE IS A REQUEST URI
if (isset($_SERVER["REQUEST_URI"]))
{
    // SAVE THE REQUEST
    $_SESSION["REQUEST_URI"] = $_SERVER["REQUEST_URI"];

    // IF A PHP SCRIPT IS NOT FOUND GO TO THE HOME PAGE
    if (preg_match('#\.php#i', $_SERVER["REQUEST_URI"]))
    {
        header('Location: /');
        exit;
    }

    // IF A NON-PHP SCRIPT IS NOT FOUND, TRY IT WITH PHP
    $arr = explode('?', $_SERVER["REQUEST_URI"]);
    $arr[0] .= '.php';
    $uri = implode('?', $arr);
    header("Location: $uri");
    exit;
}

// IF NO REQUEST URI GO TO THE HOME PAGE
header('Location: /');
exit;

Open in new window

0
 
amrshalabyAuthor Commented:
Thanks Ray, that's quite helpful. I ran phpinfo() like you suggested and the offending URL is not in any of the variables. I emailed the hosting provider (names.co.uk) and they said that they can't help and to search online forums instead!
0
 
Ray PaseurCommented:
It would seem to me that the hosting provider deserves to lose a customer for an answer like that.

Please post a link to your 404 handler with phpinfo() so I can see it in action.  If the information is in there somewhere I may be able to help you find it.  

If it is not, then you need to get a technically competent hosting company.  I use and recommend ChiHost.com because they have excellent, knowledgeable telephone support.  I have had good success using Dreamhost, LiquidWeb, Hostgator, too.  I avoid SiteGround and GoDaddy.  For dedicated hosting, Rackspace is great.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
amrshalabyAuthor Commented:
Thanks Ray, that's very kind of you. Here's a link you can use:

http://test.bdental.co.uk/ThisPageDoesntExist

You'll need to view source to see the output of phpinfo()

0
 
Ray PaseurCommented:
OK, I looked at it.  It is PHP Version 5.2.9.  The build date is ancient history: Apr 13 2010.  On the home page of PHP.NET you will find this statement: All PHP users should note that the PHP 5.2 series is NOT supported anymore. All users are strongly encouraged to upgrade...

The error script is, as you have noted, not getting the correct information from the server.  But there may be a double 404 condition occurring here, or some other screwy condition.  I noted these parts:

ENV["REQUEST_URI"] = /error
ENV["SCRIPT_NAME"] = /error.php

This would seem to suggest that something may be wrong with the way the .htaccess ErrorDocument statement is being processed.  What does your .htaccess say?

If you are using .htaccess like I showed above, to make the redirect, you may be out of luck with this hosting provider.  But before you give up on them, let's see your .htaccess file.  And you might want to ask the tech support staff to escalate the problem to their higher-level support representatives.  When you get someone that sounds like they have a clue, ask them for an example of a 404 handler written in PHP.
0
 
amrshalabyAuthor Commented:
Hi Ray, I think you may be getting a lot closer to the problem. There are two separate scripts, the .htaccess file has the 404 redirect. But there is another file that takes the .php extension off the php files. So two redirects like you mentioned.

.htaccess file:
===========

# Created with HTAdmin v4.0.20050909
# HIDE THE CONTENTS OF THIS FILE FROM BROWSERS
<FilesMatch ^\.ht.*>
order deny,allow
deny from all
</Files>
# SET THE CUSTOM ERROR PAGE PATHS
ErrorDocument 400 ./error
ErrorDocument 403 ./error
ErrorDocument 404 ./error
# SET THE PATHS FOR PASSWORD PROTECTION ROUTINES
# PASSWORD PROTECTION
# END OF TEMPLATE
# DO NOT MODIFY ABOVE THIS LINE BY HAND!!!

========================================================================

rewrite.script:
===========

match IN:Host into $ with ^bdental\.co\.uk$
if matched then
    match URL into $ with ^/(.*)$
    set OUT:Location = http://www.bdental.co.uk/$1
    set OUT:Content-Type = text/html
    set RESPONSE = 301
    set BODY = Moved
    goto END
endif


RULE_0_START:

# replace /team/ and /services/ with /
match URL into $ with ^(.*)/team/(.*)$          
if matched set URL=$1/$2
match URL into $ with ^(.*)/services/(.*)$          
if matched set URL=$1/$2

# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}

# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
  set SCRATCH:REQUEST_URI = $1
  set SCRATCH:QUERY_STRING = $2
endif

RULE_0_END:

RULE_1_START:
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

# check to see if the file requested is an actual file or
# a directory with possibly an index.  don't rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
  look for dir at %{SCRATCH:REQUEST_FILENAME}
  if not exists then
#    set URL = /index.php?q=%{SCRATCH:REQUEST_URI}
    set URL = /%{SCRATCH:REQUEST_URI}.php
    goto QSA_RULE_START
  endif
endif

# if we made it here then its a file or dir and no rewrite
goto END
RULE_1_END:

QSA_RULE_START:
# append the query string if there was one originally
# the same as [QSA,L] for apache
match SCRATCH:ORIG_URL into % with \?(.*)$
if matched then
  set URL = %{URL}&%{SCRATCH:QUERY_STRING}
endif
goto END
QSA_RULE_END:

0
 
Ray PaseurCommented:
Let's try this change in the first script.  I am not sure it will work, but it is very easy to test.

# SET THE CUSTOM ERROR PAGE PATHS
ErrorDocument 400 ./error.php
ErrorDocument 403 ./error.php
ErrorDocument 404 ./error.php

Just to check, please run a script using a URL query string and verify that the query string shows up in $_GET

Store the script with this:
<?php var_dump($_GET);

Run the script with a URL that looks like this:
/path/to/script.php?foo=bar
0
 
amrshalabyAuthor Commented:
I changed the error to error.php as you suggested. I also deleted the rewrte.script, so only the .htaccess is working. II also added a dump of $_GET to error.php.  Then I tried to access:

test.bdental.co.uk/thispagedoesntexist?testquery

No luck though... Sounds like the provider (names.co.uk) has an error in their settings somewhere?
0
 
Ray PaseurCommented:
They may have an error or they may just be ignorant of the right way to configure a web server.  It looks like HostingPlus is somehow involved.  In any case you have done all you can with their systems.  It's probably time to move to a better hosting company.  Wish there was another answer, but the good news is that hosting services are not expensive at all (pennies per day) so if you have to dump one it's no big deal.

If you decide to go with ChiHost.com call then by telephone (Business hours, Chicago time) and speak to Nick Gilbert.  Tell him I sent you.  They will treat you right.

Best of luck and cordial regards, ~Ray

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now