问题描述
我想在一个特定的文件夹中的文件丢失请求并将其重定向到 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.
我理解的为什么这是发生:基于文件的http://httpd.apache.org/docs/2.0/mod/core.html,网址不以一个斜线或http都PTED文本消息跨$ P $。
I understand why this is happening: based on the documentation at http://httpd.apache.org/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文件在同一文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!