将所有不存在的请求(文件\文件夹)重定向到根域页面404 [英] redirect any non-existent requests (files\folders) to root domain page 404

查看:85
本文介绍了将所有不存在的请求(文件\文件夹)重定向到根域页面404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有不存在的请求(文件,文件夹,子文件夹)重定向到root domain.com。当前显示的是:

I would like to redirect any non-existent requests (files\folders\subfolders) to the root domain.com. Currently it's showing:

未找到

在此服务器上找不到请求的URL / awddawd。
domain.com端口80上的Apache / xxxxx(Debian)服务器

The requested URL /awddawd was not found on this server. Apache/x.x.x.x.x (Debian) Server at domain.com Port 80

推荐答案

您可以使用提供的基本重写功能Apache的mod_rewrite模块:

You can use basic rewriting as offered by Apaches mod_rewrite module:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule - / [L,R=301]

最好是将这样的规则放在基本主机定义和目录/位置标签之间的(虚拟)主机配置中。

Best is to place such rules right into the (virtual) host configuration between basic host definitions and directory/location tags.

另一种方法是在文档文件层次结构中使用.htaccess样式的文件,但这更容易出错,更难调试,并确实降低了服务器的速度。因此,只有在您无法访问服务器配置时,才执行此操作。此类文件必须可由http服务器进程读取,并且显然必须在服务器配置中启用对此类文件的支持。拥有这样的通用规则的.htaccess样式文件最好放在(虚拟)主机 DocumentRoot 的顶级目录中。

An alternative is to use .htaccess style files in the document file hierarchy, but that is much more error prone, harder to debug and really slows the server down. So only do this if you have no access to the server configuration. Such files must be readable by the http server process and obviously support for such files must be enabled in the server configuration. A .htaccess style file holding general rules like this probably is best placed right inside the top level directory of the (virtual) hosts DocumentRoot.

这篇关于将所有不存在的请求(文件\文件夹)重定向到根域页面404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆