如何使用ErrorDocument来重定向到PHP文件在同一文件夹?

编程入门 行业动态 更新时间:2024-10-17 07:37:13
本文介绍了如何使用ErrorDocument来重定向到PHP文件在同一文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在一个特定的文件夹中的文件丢失请求并将其重定向到 program.php 的文件夹中。

I want to take requests for missing files in a specific folder and redirect them to program.php in that folder.

这是一个程序,我会用很多不同的地方,我会preFER避免指定在htaccess的文件的文件夹的名称。

This is a program I will use a lot in different places, and I would prefer to avoid specifying the name of the folder in the htaccess file.

我曾尝试只是把:

errordocument 404 program.php

但结果是,浏览器只是打印出program.php并不会执行program.php。

but the result is that the browser just prints out "program.php" and doesn't execute program.php.

我理解的为什么这是发生:基于文件的httpd.apache/docs/2.0/mod/core.html,网址不以一个斜线或http都PTED文本消息跨$ P $。

I understand why this is happening: based on the documentation at httpd.apache/docs/2.0/mod/core.html, url's that don't begin with a slash or http are interpreted as a text message.

现在的问题是如何解决这个限制能够访问同一个文件夹中。

The question is how to get around this limitation to be able to access the same folder.

推荐答案

我结束了使用的重写规则,而不是ErrorDocument的

rewriteengine on rewritecond %{request_filename} !-f rewriterule ^(.+).jpg$ program.php?i=$1.jpg [L]

第二行验证该文件不存在,从而使现有的图像将正确地被显示。

The second line verifies that the file does not exist, so that existing images will be shown correctly.

更多推荐

如何使用ErrorDocument来重定向到PHP文件在同一文件夹?

本文发布于:2023-11-01 13:02:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文件夹   重定向   文件   在同一

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!