Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
793 views
in Technique[技术] by (71.8m points)

.htaccess to redirect images

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 ?

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

but i'm getting stuff like

http://www.yoursite.com/images/page/images/this.jpg
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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

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.

Examples:

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

Or just:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...