Show failure link in 404 error custom page - .htaccess

Is it possible to show the user the link or the file, which can not be found through the html code of a 404 error custompage?
I asked google, but could not found any informations.
Also I do not know php and would now wondering
if it would be possible only with htaccess and html?
If not, what could I do with php, while using the htaccess redirect?
There are any simple ways?
My htaccess:
ErrorDocument 404 /funktion.fehler.php

If you're using the error document:
ErrorDocument 404 /funktion.fehler.php
Then you can use a couple of php variables. Something like:
print('The URL ' . $_SERVER['REQUEST_URI'] . ' does not exist');
You can also use $_SERVER['REDIRECT_URL'].

Related

Use .htaccess get Referrer URL from a 404 page

I am using .htaccess to get the Referrer URL. For example, if someone clicks the link example.com/dogfood-post-1 and the post is not found, how can I get that URL example.com/dogfood-post-1 in my 404.php page?
ErrorDocument 404 /404.php
Not really a full answer as it depends on specific configuration, but this should help you.
Add var_export($_SERVER) to your 404.php and see which key contains the value you need.
If you just want the url on the domain.com/dogfood-post-1 you could use:
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
source: get full url stackoverflow
if you send them to another page you could set a session and put the url in the session and then display it on the 404 page.
Instead of redirecting users to a 404 page you should show them the 404 error page. In your .htaccess you can add:
ErrorDocument 404 /appName/404.php
Put your absolute path before the 404.php in order to show it properly.

htaccess ErrorDocument with Subdomains

So I recently tried to make my own 404 page. It looks good, but after hours of searching how to add it (didn't work), I give up... How can I get the same ErrorDocument on every subdomain with this structure?
/var/www
-main site
-.htaccess
-subdomain
-.htaccess
-error
-error***.html (*** = which error, 404 etc)
...
I tried inheriting .htaccess in /var/www, but it gives me a error:
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
How can i do this? Every try either just gave me "/error/404.html" as html or encountered an error. The document root is in the Subdomains folder, that's the problem. And going back a directory in .htaccess doesn't work (../error).
Well, it seems like it doesn't work. I've now just linked a error.php in every directory and there the htaccess links to them

.htaccess Doesn't work good (404 page)

I make .htaccess file for my website to send the visitor to the error page If he make an undefined url
The problem is if make the website like this xxxx.com/index.php/something
That doesn't send me to the error page but it's show the index page without images
.htaccess file
ErrorDocument 404 http://xxxxxxxxxxxxx.com/error
This is a known behaviour of Apache. It's got nothing to do with the error document.
Generally, you may be able to reject anything after /index.php by setting the AcceptPathInfo parameter in your .htaccess:
AcceptPathInfo off
But that would probably defeat your purpose, as your index.php file couldn't accept any paths any more and it sounds like that's something it should do.
Likely the best solution for you is to use absolute paths in your images and CSS:
<img src="/images/myimage.gif">
If xxxx.com/index.php/something is an invalid URL, that is something you need to handle inside your PHP application. ErrorDocument won't help you here because it can't know what is an invalid URL for index.php and what isn't.
Set Apache's AcceptPathInfo directive to Off.

404 Redirect Error with .htaccess

I'm running a website on a local server (using WAMP Server) and I'm trying to test to see if my 404 page would work, but when I try to navigate to a nonexistent page, I get an error that says:
The requested URL /dsf/sdkmf was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.
My 404 page is in the root folder with all my other pages and my .htaccess Error Document handle is listed as:
ErrorDocument 404 /404.html
I don't know why it's throwing me this error much less how to fix it, does it have something to do with my WAMPServer configuration?
Never mind - I figured out how to solve it on my own - apparently you have to use the direct path to the file - even if it's in the root directory of the site itself!

htaccess - rewriting rules

Google Webmaster tools gives me a hint that I have 2 pages with the exact same content.
For example:
/airports/romania/115.php
/airports/romania/115.phphey1
In the htacces file i have this:
RewriteRule airports/(.*)/([0-9]{1,}).php airports_list.php?airport=$2&country_air=$1
I've checked and double checked and triple checked all my code in airports_list.php and every other file on the server. I can't find "hey1" anywhere.
In order to solve my problem, I think I have to redirect a link like www.mydomain.com/airports/romania/115.phphey1 to a 404 page.
How do I do that ?
The following is also working inside my .htaccess file :
ErrorDocument 404 http://www.mydomain.com/404.php
If you put a dollar sign at the end of the regex, it stops matching and so garbage at the end of '.php' and goes to the 404.
RewriteRule airports/(.*)/([0-9]{1,}).php$ airports_list.php?airport=$2&country_air=$1

Resources