开发者

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

my quest开发者_运维百科ion 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/pets) if a user types in http://mywebsite.com/petsd by accident, I want the user to be redirected to the home page. Anyone know how this can be done? Thanks.


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


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


you can use mod_rewrite

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [R]


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜