重定向内部的路径,如果资源不存在 [英] Redirect internal to path, if resource doesn't exists

查看:168
本文介绍了重定向内部的路径,如果资源不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从内部重定向到其他位置,因此用户将不会看到脚本的位置/ URI,如果图像不存在的:

i am trying to redirect internally to another location, so the user won't see the "script" location / uri, if an image does not exists:

RewriteCond %{REQUEST_URI} ^/resources/img/tires [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/img/tires/(.*)$ reifen/imagematch/$1 [L]

例如,如果我要求图像:

For example if i request an image:

的http://domain.tld/resources/img/tires/manufacturer/image.jpg - >图像的存在,直接服务于图像

http://domain.tld/resources/img/tires/manufacturer/image.jpg -> Image exists, directly serve the image.

如果我要求:

的http://domain.tld/resources/img/tires/manufacturerX/image2.jpg - >图像不存在, 调用它位于脚本的http://domain.tld/reifen/imagematch/ {manufacturerX / image2.jpg}

http://domain.tld/resources/img/tires/manufacturerX/image2.jpg -> Image does not exist, call the script which is located at http://domain.tld/reifen/imagematch/{manufacturerX/image2.jpg}

我有什么在我的重写规则进行修改,从而使显示的例子将能正常工作?

What do i have to modify in my rewrite rules, so that the shown example will work correctly?

最好的问候和感谢!

推荐答案

您可以使用根的.htaccess规则:

You can use this rule in root .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/img/tires/(.+)$ /reifen/imagematch/$1 [L,NC]

这篇关于重定向内部的路径,如果资源不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆