简体   繁体   English

404错误页面重定向回首页

[英]404 error page redirect back to home page

I have a website www.thewritedesign.co.uk. 我有一个网站www.thewritedesign.co.uk。 My site is based on includes. 我的网站基于包含。 My navigation at the top of the site all use achor links and the site is all one page. 我在网站顶部的导航全部使用achor链接,并且该网站都是一页。 I have an error page, so when you type www.thewritedesign.co.uk/euskdfzxcahsz, the remaining /euskdfzxcahsz stays in the URL and my navigation links do not work when you land on my error page because they have #services #about etc as the link. 我有一个错误页面,所以当您键入www.thewritedesign.co.uk/euskdfzxcahsz时,其余的/ euskdfzxcahsz保留在URL中,并且当您进入我的错误页面时,我的导航链接不起作用,因为它们具有#service #about等作为链接。

I have wrote an if statement for my other page "Terrms and Conditions" if you land on /terms-and-conditions that if you use the navigation links at the top of that page, you can get back on track so the links are now /index#services /index#about etc. 如果您使用/ terms-and-conditions,我为其他页面“ Terrms and Conditions”写了一个if语句,如果您使用该页面顶部的导航链接,则可以回到正轨,因此链接现在/ index#services / index#about等。

My question is. 我的问题是。 If you land on www.thewritedesign.co.uk/euskdfzxcahsz, is there an if statement I can use to say whatever page you land on which doesn't exist, go back to /index#services /index#about 如果您登陆www.thewritedesign.co.uk/euskdfzxcahsz,是否有if语句,我可以用它说您登陆的任何页面都不存在,请返回/ index#services / index#about

Thanks 谢谢

One of the better ways (in my opinion) is to let the htaccess file handle this issue for you. 更好的方法之一(我认为)是让htaccess文件为您处理此问题。

The htaccess file has a RewriteEngine that allows you to do a lot of things in terms of URL handling. htaccess文件具有RewriteEngine,可让您在URL处理方面做很多事情。 What's most interesting for you, would be the ErrorDocument 404 handling. 对您而言最有趣的是ErrorDocument 404处理。

A 404 error is basically a "dead link" , meaning that whatever destination the user is trying to arrive at, doesn't exist. 404错误基本上是“死链接” ,这意味着用户尝试到达的任何目的地都不存在。 You can then choose to redirect the user through an error handling in the htaccess file. 然后,您可以选择通过htaccess文件中的错误处理来重定向用户。

Example: 例:

RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/index.php#services

Change the URL in the example to fit your needs. 更改示例中的URL以适合您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM