how to redirect non existent link on website back to the home page

前端 未结 4 1122
后悔当初
后悔当初 2021-01-22 09:45

my question is how to redirect any non existent link on my website back to the home page. For example; imagine i have a page called \"pets\" on my site (http://mywebsite.com/pet

相关标签:
4条回答
  • 2021-01-22 10:13

    Set ErrorDocument 404 /index.html in your .htaccess file

    0 讨论(0)
  • 2021-01-22 10:21

    Using mod_rewrite you can handle 404 (page not found) like this:

    RewriteEngine on
    Options +FollowSymlinks -MultiViews
    
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule . / [L]
    

    This will preserve original link in the browser but will show your home page.

    0 讨论(0)
  • 2021-01-22 10:30

    you can use mod_rewrite

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php [R]
    
    0 讨论(0)
  • 2021-01-22 10:32

    Equip the 404-page with a javascript redirect. Make sure it is timed, so visitors can see what happened.

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