Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess-如果用户尝试直接访问文件,是否重定向到错误页?_Php_.htaccess_Redirect - Fatal编程技术网

Php htaccess-如果用户尝试直接访问文件,是否重定向到错误页?

Php htaccess-如果用户尝试直接访问文件,是否重定向到错误页?,php,.htaccess,redirect,Php,.htaccess,Redirect,我有一个网站,其中主目录包含一些文件,我不想使用如下URL直接访问: http://website.com/somefile1.ext1 http://website.com/somefile2.ext1 http://website.com/somefile1.ext2 http://website.com/somefile2.ext2 http://website.com/404 当前,如果您在浏览器中输入URL,它们将下载。相反,我想将它们重定向到如下错误页面: http://webs

我有一个网站,其中主目录包含一些文件,我不想使用如下URL直接访问:

http://website.com/somefile1.ext1
http://website.com/somefile2.ext1
http://website.com/somefile1.ext2
http://website.com/somefile2.ext2
http://website.com/404
当前,如果您在浏览器中输入URL,它们将下载。相反,我想将它们重定向到如下错误页面:

http://website.com/somefile1.ext1
http://website.com/somefile2.ext1
http://website.com/somefile1.ext2
http://website.com/somefile2.ext2
http://website.com/404
我在网上找到了这个片段,但它不起作用,也没有重定向:

<Files ~ "\.(ext1)$">
  Order allow,deny
  Deny from all
</Files>

像这样试试我现在还没试过

RewriteEngine On
RewriteCond %{REQUEST_URI} \.ext\d$
RewriteRule ^ 404 [R=301]

像这样试试我现在还没试过

RewriteEngine On
RewriteCond %{REQUEST_URI} \.ext\d$
RewriteRule ^ 404 [R=301]
试一试


全盘否定
如果要拒绝所有用户的访问,则不需要使用Order指令

试试看


全盘否定

如果要拒绝所有用户的访问,则不需要使用Order指令

我知道我的htaccess正在运行,但这似乎不起作用。它仍然下载文件。404是一个php文件,或者你有其他一些规则来处理它,因为上面的内容对我有用。我编辑了上面的文章,我使用了重定向函数,但它应该只适用于.php文件,但可能会干扰代码。不应该。请在当前规则之上尝试我的规则可能该规则缺少
L
标志。我知道我的htaccess正在运行,但这似乎不起作用。它仍然下载文件。404是一个php文件,或者你有其他一些规则来处理它,因为上面的内容对我有用。我编辑了上面的文章,我使用了重定向函数,但它应该只适用于.php文件,但可能会干扰代码。不应该。在当前规则之上尝试我的规则可能规则缺少
L
标志。我不知道这是否有效,但是添加
ErrorDocument 403/404.php
可能会显示所需的错误页面。我不知道,如果有效,但是添加
ErrorDocument 403/404.php
可能会显示所需的错误页面。