I am redirecting the pages to 404.php if the page is not found from IIS settings.
My problem is that I would like to detect the LINK that they were looking for.
For example:
if some one access to http://www.site.com/nosuchpage it will redirect to 404.php but using $_SERVER["HTTP_REFERER"] I am not getting url where the user came from.
Please help.
If you are redirecting them to 404.php via htaccess, i.e.
ErrorDocument 404 /404.php
Then you should just be able to use $_SERVER['REQUEST_URI'] as the URL they requested should still be the url that wasn't found.
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 two domain names examplesite.com and examplesite.net but they point to the same hosting server i.e. website.
Now I have written an .htaccess file because I wanted to show custom 404.html file.
Here is the code in my .hraccess file.
ErrorDocument 404 http://www.examplesite.com/404.html
When a user gets a 404 error when he is on examplesite.com he is redirected to the above address which is ok.
But when a user gets 404 error when he is on examplesite.net he is redirected to the above address i.e. 'examplesite.com/404.html' .I wanted the user to stay on examplesite.net/404.html.
I do not want the url for the redirection.
Is there a solution for this? Please help.
Can I apply condition or something like that?
You can simply use
ErrorDocument 404 /404.html
The domain prefix is not needed.
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.
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
I know I can redirect to a 404 page with htaccess, but can I just include the custom 404 page I have into the URL that is causing the 404? For example, someone types in blahwat.php, which is not on the server, can I keep them on that page but instead of the apache 404 can I have it include my custom 404 page?
Using ErrorDocument does not redirect, so I don't know why you're bringing redirection up.
In any case, if there was a page at the URL then you wouldn't be getting a 404 in the first place.