How to redirect wrong urls to 404 page?
For example, subdomain.domain.com is fine, but if users enter subdomain.domain.com/asadasd/ada or anything like that, index page is still shown. How to make these mistyped urls show 404 page?
Im using php, mysql, cpanel ect ect.
Yes, I am already using htaccess with ErrorDocument 404 /error.php but no luck here.
you can use '.htaccess'
put this line in .htaccess ErrorDocument 404 /error.php and create error.php file in your root folder.
You will handle the redirection with .htaccess errordocument 404 /404.php
Please follow the complete process in this link
It will help you a lot.
error redirection link tutorials
Related
I would like to place a htaccess file in the root of a site and have this htaccess file redirecting 404 errors to the subfolder mysite.com/old using the url value in the redirection so it becomes like mysite.com/old/articel1.html
In essence, I need a dynamic redirect from mysite.com/anyPage.html to mysite.com/old/anyPage.html but only if a 404 error happens.
I have looked into rewrites but I need Google to see that the url has changed permanently.
I have tried googling it and tested many examples but none worked like I need it to be.
Can you help? :-)
Thank you :-)
You can redirect with your .htacces file
This should looking like this
ErrorDocument 404 /old/anyPage.html
And yes, this is not a 301, because you cant redirect 404 as 301 automaticly.
Monitor your site with Google Console and add your redirect manually like this
RewriteEngine On
Redirect 301 /anyPage.html /old/anyPage.html
I have this 404 redirection in my .htaccess file :
ErrorDocument 404 /404.php
It works fine when I try to access a page that doesn't really exist on my server.
The problem is that when I return my own HTTP 404 status in a page that really exists on the server, it doesn't redirect me to the 404.php page, but the browser displays a standard 404 error.
I return my own HTTP 404 status when I have a wrong url parameter for example.
Can you help me to define the rule in the .htaccess file, please?
in your .htaccess file you should have this rule
RewriteEngine On
ErrorDocument 404 /404.php
and if you want to simulate this error in anyplace other than typing it manually in the header you should use http_response_code
PHP code
<?php
http_response_code(404);
include('my_404.php'); // provide your own HTML for the error page
die();
How I can redirect to my error page?
My directory structure:
Inside .htaccess file:
ErrorDocument 404 /Index.php?controller=Main&action=error
I don't know how correctly to tell, but it redirects me to ../ back one level.., in xampp ../ will be Index file...And show:
I want on 404 error redirect to Index.
I try in .htaccess file add this line:
ErrorDocument 404 Index.php?controller=Main&action=error
but without / flash its show text like this:
Enter an absolute URI, like ErrorDocument 404 /Index.php?controller=Main&action=error
See https://httpd.apache.org/docs/2.4/mod/core.html#errordocument
I am trying to track all those link that causes 404.i tried $_SERVER['HTTP_REFERER'] on 404 page but it doesn't work for me .
NOTE: i don't wanna use google analytic API. Is there any other possible way
Create a .htaccess file that will redirect to a 404 page on 404 error.
Add this code to your .htaccess file: ErrorDocument 404 /404.php and in the root of your code create a file called 404.php. In that 404.php file you can do all the handling of the error.
$_SERVER['REQUEST_URI'] should have the URL that was requested in the browser.
Also make sure that you are loading the 404 page and not redirecting to the 404 page.
The below is my .htaccess file placed in the root
ErrorDocument 404 http://www.abc.com/404.php Redirect
/services/something.php http://www.abc.com/index.php
The second line is irrelevant I guess.
The problem is that it redirects any non existent file to my 404.php perfectly when I run it in my local WAMP server. But with the same is not happening when I upload it to my server. What could be wrong?
Also, if I write
ErrorDocument 404 /404.php instead of ErrorDocument 404 http://www.abc.com/404.php it won't even work in the localhost.
I get the error message saying
The requested URL /abc/xxxx was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Why does this error occur when every website I refer has recommended ErrorDocument 404 /404.php
first of all make sure that the 404.php is present in the proper location and http://www.abc.com/404.php is working properly.
if both 404.php and .htaccess are present in the same root folder, then
try changing following line in .htaccess file
ErrorDocument 404 /404.php
to
ErrorDocument 404 /root/404.php