简体   繁体   English

php htaccess重定向404错误页面

[英]php htaccess redirect 404 error page

I am building a LAMP application www.testing.com and I have an image url www.testing.com/image/folderA/a.jpg . 我正在构建一个LAMP应用程序www.testing.com并且有一个图像URL www.testing.com/image/folderA/a.jpg

I want to have a rewrite rule in .htacess such that if user navigates to images that do not exist in /image/foldera, he will be redirected to another image with the url www.testing.com/image/folderB/b.jpg . 我希望在.htacess中有一个重写规则,以便如果用户导航到/ image / foldera中不存在的图像,则他将被重定向到另一个具有URL www.testing.com/image/folderB/b.jpg图像。

This is my code. 这是我的代码。

RewriteRule ^image/folderA/(.*\.(jpg|gif|png))$ http://%{SERVER_NAME}/image/folderB/b.jpg [R=404,L]

However, this is not working as www.testing.com/image/folderA/a.jpg , which is supposed to return an image, gives an 404. Any idea why? 但是,这不起作用,因为应该返回图像的www.testing.com/image/folderA/a.jpg给出404。为什么?

When using the R flag you need to keep the following in mind: 使用R标志时,请注意以下几点:

However, if a status code is outside the redirect range (300-399) then the substitution string is dropped entirely, and rewriting is stopped as if the L were used.

http://httpd.apache.org/docs/trunk/rewrite/flags.html#flag_r http://httpd.apache.org/docs/trunk/rewrite/flags.html#flag_r

This means that your rewrite rule is dropping the substition string and redirecting all requests to specified files to the built-in 404 page. 这意味着您的重写规则将删除替换字符串,并将所有请求重定向到指定的文件到内置404页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM