serve 404 page from a folder with static files when using Joomla - apache

I have a Joomla site running on Apache and Ubuntu 12.04. I wanted to show a custom 404 pages to be shown when a 404 error occure. I have made necessary changes to error.php file in my template directory to redirect it to '/404' directory where I have an index.html file with many images,css and java script.
Now when accessing a non-existent page, Joomla is redirecting me to root/404 but there I get a 403 Forbidden error from appache. The 404 directory is located inside 'htdocs' directory of Joomla installation.
Additional info:
1. I don't want to convert my 404 page into a Joomla template or article.
2. I am using a Joomla AMI from Bitnami on Amazon web service

If you redirect to a 404 page, you corrupt the error mechanism. The client will never get that 404 status, but a 200 on successful redirect to your error page.
Instead, you should modify your template's error.php to
send the 404 Not Found header
directly send the error page using readfile()
You might have to adjust the asset paths within your error page.

That's totally wrong, working with static pages does not mean that you have to overcome Joomla's routing.
You should either override the error Page view or use custom error pages.
Take a look at Joomla's documentation.http://docs.joomla.org/Custom_error_pages
Nibra was totally right about breaking the mechanism but still using a readfile() seems as an overkill.

Related

Apache htaccess ErrorDocument directive not working

I found a vulnerability for content-spoofing on my webpage.
This URL:
https://www.mygreatsite.com/www.mygreatsite.com%20has%20moved%20to%20www.evilsite.com.%20CHECK%200UT%20H0W%20COOL%20THE%20NEW%20SITE%20IS!%20Sadly,%20the%20file%00
Apache Output:
Not Found
The requested URL /www.mygreatsite.com has moved to www.evilsite.com. CHECK 0UT H0W COOL THE NEW SITE IS! Sadly, the file was not found on this server.
--
The URL Overrides the Apache-Error and outputs the text added to the URL in the Browser, along with a 404-Error.
Actually, all requests to the server should be redirected to the CMS (Typo3) which in turn handles the 404-error and shows a custom page.
When I enter an URL that doesn't exist, this works perfectly. Just the above mentioned URL screws everything up.
Interestingly, when I delete the «%00» from the end of the URL, the request is forwarded to the CMS and the correct error document is displayed.
I tried to add a separate ErrorDocument-Directive to the htaccess-file - with no success.
Any ideas what goes wrong and how I could solve this?
As Anubhava points out, when a NULL-Byte is detected, Apache doesn't load any modules and just throws the 404. That's why ErrorDocument and mod_rewrite in the htaccess don't work.
[Edit for clarification]
%00 or in Hex \x00 is a NULL byte. When web server finds a NULL byte at the end then web server thinks it is a spoofing request and considers it to be dangerous to be processed by any directives.
Due to security reasons web server doesn't load any modules for this request and returns a 404 / Not found status. Browser shows default 404 page with your decoded URL just below Not Found text.

TYPO3 404 Error handling

There are a lot of tutorials about error 404 handling and different solutions.
If I'm using TYPO3 6.1, Fluid/Extbase and RealURL, what is the best way to make an Error 404/500 handler that uses the page Uid = 13 (error/notfound/)
If you have an error 500, TYPO3 will not be able to handle it since it is "crashed". For 404 handling you will see a list of possibilites in the install tool, section [pageNotFound_handling].
The most straight-forward way for a website with one language is to enter an absolute URL to the [pageNotFound_handling] field. The URL could point to a TYPO3 page or a static HTML site. TYPO3 will not redirect to this page, but output this page and send the proper 404 status.

With static content: Apache custom 404 page that returns 404 error

I have the same problem as Apache custom 404 page that returns 404 error, but additionally I use html files and no scripting language.
Is there a possibility to configure Apache in a way that it returns the page www.example.com/404.html with a 404 status when requested by the browser?
I am giving an answer myself, I am not sure if it should be a comment.
I realised that I tried to fix a workaround and not an actual problem. Originally I wanted to show a 404 page using
ErrorDocument 404 /subdirlevel1/404.html
However the error document itself used relative paths and so it only worked when the path of the requested document was in the right subdirectory level. What I mean is the following:
http://example.com/subdirlevel1/nonexisting.html
would produce a proper 404 document, as the path to the css stylesheet was at a proper relative path. However
http://example.com/subdirlevel1/subdirlevel2/nonexisting.html
would not work. I fixed this by using absolute paths in 404.html
Doing it the way I've tried in my question would be bad style, as a request to an existing file with a proper delivery of that file should not result in a 404, but in a 200.

Apache ErrorDocument: showing 404 URL

I suspect this can't be done, but here goes anyway. Is there a way, on a static site, to show the URL the user is trying to reach when you use the Apache directive ErrorDocument to redirect a 404 File Not Found error to a custom page? For instance, if you try:
http://www.fredriley.org.uk/dingbat/arsebiscuits
the default 404 error says:
The requested URL /dingbat/arsebiscuits was not found on this server.
So the URL must be in an environment variable. Can I get at that in a custom error document? I'd like to tell users the URL rather than just give them a generic error document. I know I can do this easily enough in PHP, but the site comprises static HTML docs only.
Having a static site does not prevent you from having a dynamic error page. You can use whatever server-side technology your hosting service offers.
If you can use PHP, you can simply pick a static template, change its extension to *.php and add a little dynamic snippet:
<p><?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?></p>
If you can use SSI, it's very similar:
<p><!--#echo var="REQUEST_URI" --></span></p>
The REQUEST_URI variable contains the local part of the URL as typed by the user (except hash). It's a good choice.

I want all page requests to point to a single page

The wrinkle is that the pages being requested are aspx pages and they are no longer present. I want any request coming to the root domain (and any subdomain like www) to redirect to a single page in the root directory (namely index.html) I went into the IIS admin tool, selected the domain and tried to direct to a url (http://mydomain.com/index.html) but that caused index.html to be appended multiple times and resulted in an error.
What is the best way to do this, so that any http request ot hsi domain goes to the index.html page?
Thanks in advance.
Warren
You can achieve this using the ASP.Net App_Offline feature; if you place a file in the root of your website called App_Offline.htm, the contents of that file will be returned in response to all incoming requests.
Or find your default 404.html file and put some redirection code into it