Need to render HTML (extension) file on my website - apache

I need to render following pages on my website:
http://xxx/packages/most-popular-hennan-boracay-regency.html
http://xxx/packages/super-special-with-pickup-la-carmela.html
http://xxx/packages/adventures-boracay-atv-buggy-car.html
But whenever I hit these URLs in my browser, my URL is transformed in following:
http://xxx/packages/most-popular-hennan-boracay-regency
http://xxx/packages/super-special-with-pickup-la-carmela
http://xxx/packages/adventures-boracay-atv-buggy-car
And a 404 not found error is displayed.
I have checked my .htaccess and found nothing suspicious.
Also checked MIME Types section in CPanel.
Still unable to figure it out.
So, please help.

Related

Serve files from dcos as .html docusaurus

Problem
Noticing when I upload my 'build' content to the server, the md files in docs are breaking.
Not sure why, but there are clearly '.html' files.
But reloading the page doesn't work and i18n doesn't work either.
What confuses me
So, I tried directly accessing the page with '.html' link.
Just to show you,
http://coding-insight.com/docs/python/start/python/ displays 404 when using direct link.
However, using the site's menu bar works.
Reloading results in 404.
But there are clearly html files in the server.
https://user-images.githubusercontent.com/78584173/179334770-46bb6e02-cf6a-4a76-be40-c3fe71038622.png
So, I tried accessing html files directly.
https://coding-insight.com/docs/python/start/python.html
It works. Reloading works.
Question
So, are there any way I could access the html files directly rather than using those '/' at the end?
Is it a bug?

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.

Error 404 for file download without browser redirection?

on a website I display links to PDF files.
When the first time call for a file arrives, the request gets redirected to a php-script that generates and returns the file. Additionally, it saves the file to the linked location so next time it will be directly availibe. I send the pdf mime type to make the browser open a download dialog instead of redirecting.
Due to reasony beyond my control, one out of 20 files cannot be generated.
How to respond?
Error 404 or 500 would direct the browser to an error page, while sending a mime-type would let the user download an empty / defect pdf file. Is there an established best practise? How to let the user know that a file link is broken, yet keep him on the site without redirect?
I had the same problem and solved it as follows:
If you have link to file, for example:
<a download href="/files/document.pdf">Click to download</a>
And if you don't want the browser redirect to blank/error page if the file doesn't exist, just reply with 204 without any content.
Nothing will happen, the user will stay where he is without redirection.
In php it would look something like this:
if (!readfile("/files/document.pdf") {
http_response_code(204);
die();
}

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

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.

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.