I have done a lot of searching and it doesn't seem like there was a way to provide a template suggestion for the core 404 error page, so I have been tinkering with the CustomError module, and can not get it to consistently output the referring page in my code. This is not limited to this module, since if I add it to a node with the PHP filter turned on, it behaves the same way. When I go to a bad URL, the page outputs but the URL is not displayed. If I then flush the Drupal cache, the referring URL is output. If I refresh again, it is not displayed.
In a static environment, I was able to accomplish this with an SSI include:
<!--#echo var="HTTP_HOST" --><!--#echo var="REQUEST_URI" -->
Here is the code I am using in Drupal:
<?php print referer_uri(); ?>
Thanks.
Comments
Not sure I follow. In order
Not sure I follow. In order to specify a custom error page, you can specify one under admin/settings/error-reporting, say call it '404'
In your theme's template.php file, you can do something quick and dirty like this to theme it (with clean-urls)
Then just create a template file with your specific customisations, page-404.tpl.php and refresh the cache.
Ok, I've got that part down,
Ok, I've got that part down, where Drupal will use my custom page-404.tpl.php template to theme that node. I am still unable to get the referrer URL to display consistently using:
Hmm, I'm not having an issue
Hmm, I'm not having an issue trying to recreate the same thing.
Have you tried prining $_SERVER['HTTP_REFERER'] directly? Referer_uri is just a wrapper for it.
Ok, I duplicated the
Ok, I duplicated the problem.
I'm trying to figure out why $_SERVER['HTTP_REFERER'] isn't populated for the error page. Will return if I find out
Ok, it works fine, but only
Ok, it works fine, but only as long as the user-agent has a valid entry for it to use.
Ie, I get nothing if I haven't visited a page begin with. If I manually enter a link into the address bar, it won't. This make sense when we consider the definition:
Personally I'd do away with this, and if you're not against a bit of Javascript, investigate the document.referrer method.
Thanks for all your help. I
Thanks for all your help. I misunderstood referer_uri. What I was looking for was request_uri. I am getting the output I am looking for using this code:
Does $_SERVER["HTTP_HOST"]; need to be passed through a sanitizing function, or is there a better way to write this?
Ideally yes, you'd be wanting
Ideally yes, you'd be wanting to replace it with drupal_valid_http_host (http://api.drupal.org/api/function/drupal_valid_http_host)
print "http://" . drupal_valid_http_host($_SERVER["HTTP_HOST"]). request_uri();It looks like
It looks like drupal_valid_http_host is boolean and is only printing true or false. I was able to use check_url instead:
Thanks for all the help!
Urk, it is. Sorry about that,
Urk, it is. Sorry about that, not with it today :)