How do I redirect 404's to index.html and rewrite the URL to the home page URL?

后端 未结 2 1513
挽巷
挽巷 2020-12-10 12:16

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:

相关标签:
2条回答
  • 2020-12-10 12:30

    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.

    0 讨论(0)
  • 2020-12-10 12:38

    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.

    0 讨论(0)
提交回复
热议问题