I changed a bulky, complex website into a small one-page website, so users need to be redirected from 404s to index.html.
I put this in .htaccess:
ErrorDocument 404 /index.html
If you type mydomain.com/lalalalala, this redirects to the home page content (mydomain.com/index.html), but the URL bar still says mydomain.com/lalalalala.
How do I redirect 404s to index.html and rewrite the URL to mydomain.com?
EDIT:
I'm using Bluehost.
The simplest way to redirect to another URL is to use an HTML <meta> tag with the http-equiv parameter set to “refresh”. The content attribute sets the delay before the browser redirects the user to the new web page. To redirect immediately, set this parameter to “0” seconds for the content attribute.
Click the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.
404s should not always be redirected. 404s should not be redirected globally to the home page. 404s should only be redirected to a category or parent page if that's the most relevant user experience available. It's okay to serve a 404 when the page doesn't exist anymore (crazy, I know).
You can use these 2 lines at the top of your .htaccess:
DirectoryIndex index.html
ErrorDocument 404 http://domain.com/
DirectoryIndex
will make http://domain.com/
load http://domain.com/index.html
by default and use of http://
in ErrorDocument
will make it redirect to new URL.
Try below code :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
ErrorDocument 404 /index.php
It's any 404 url
to your home page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With