使用ErrorDocument 404将所有请求重定向到index.php

时间:2019-11-13 21:26:12

标签: apache .htaccess

我想对所有请求使用一个index.php文件,除了存在的文件,例如图片,CSS和JS。

我还想对所有请求强制使用斜杠。

我还想拥有一个包含不应访问的系统文件的文件夹。但是我不希望任何人看到此文件夹或这些文件存在。

我也希望所有这些尽快完成。

我认为我可以使用此htaccess:

RewriteEngine On

# Force trailing slash on the end
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

# Handle all request from one index.php file
ErrorDocument 404 /index.php

# Prevent system folder from being accessed
RedirectMatch 404 ^/system/?$

在index.php中,我将确定页面是否存在并相应地设置响应代码。

我不是专业人士,但似乎可以。但是我不知道 ErrorDocument 404 /index.php 是否会减慢任何速度,例如。影响服务器如何在RAM内存中缓存请求?

0 个答案:

没有答案
相关问题