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.
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
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 want to have a custom 404 page on my apache web-server, therefore I edited the config file of the site and entered this line:
ErrorDocument 404 /404.php
Unfortunately this doesn't work for all cases. If the user enters something like http://mywebsite.com/ldsakjfdalkj, it works fine. But if the user enters something like http://mywebsite.com/adf/adf/df/a, I have a lot of problems with my paths. For example, in the second case, the 404.php looks up the background file in ./adf/adf/df/a/images/background.jpg and the URL in my browser stays the same. Is there a way to properly redirect to http://mywebsite.com/404.php?
I am using htacces for redirection
ErrorDocument 404 /404.php
By this code i am only able to redirect
www.abc.com/sfgsg
to custom error page.
I want to redirect
www.abc.com/services/fsdgg
to also on custom error page.
or
www.abc.com/product/dsgdfsg
to
custom error page. How this could be done. Guide
If /services or /product are real folders (as opposed to dynamic uri mapping) you can place folder-specific .htaccess files in each that you want a custom 404 page for. Each .htaccess file would specify what ErrorDocument directives are to be followed for that path.
Alternatively, you can have your php code handle the custom mapping. Apache adds the system variables REDIRECT_URL and REDIRECT_STATUS to allow error pages to figure out where the user tried to go and why they failed to go there. See the Apache docs for exactly how/what it does.
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.