.htaccess 重定向图像 [英] .htaccess to redirect images

查看:40
本文介绍了.htaccess 重定向图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是 htaccess 重定向规则的新手,并且已经成功重定向了我的页面,以便显示漂亮的 URL,但是有没有办法重定向图像,使其不是相对的?有没有一种方法或功能可以让我重定向图像而不用一个一个地改变它?

i'm still new to the redirectrule thing from htaccess and have successfully redirected my pages so that the pretty URL shows up, but is there a way to redirect the images so that it is not relative? Is there a way or function that allows me to redirect images without changing it one by one ?

就像我重定向页面后一样,我得到了相对 URL,因此我的图像在它们的链接中显示了一些额外的东西.

Like i after redirecting the page, i get relative URL, hence my images are showing something extra in their links.

所以这是图片的实际网址

so this is the actual url to the image

http://www.yousite.com/page/images/this.jpg

但我得到了类似的东西

http://www.yoursite.com/images/page/images/this.jpg

推荐答案

我不确定这是否会解决问题,但您可以在每个页面中使用 BASE 元素代替修改所有链接定义基本 URI:

I am not sure this will solve the problem, but instead of modifying all the links you could use the BASE element in each page to define a base URI:

来自 http://www.w3.org/TR/html4/struct/links.html#h-12.4:

当存在时,BASE 元素必须出现在HTML 文档,在任何引用外部源的元素之前.这BASE 元素指定的路径信息仅影响元素出现的文档.

When present, the BASE element must appear in the HEAD section of an HTML document, before any element that refers to an external source. The path information specified by the BASE element only affects URIs in the document where the element appears.

示例:

 <HEAD>
   <BASE href="ImagesBasePath">
 </HEAD>

或者只是:

 <HEAD>
   <BASE href="/">
 </HEAD>

这篇关于.htaccess 重定向图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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