dqd72925 2012-10-29 14:26
浏览 57
已采纳

.htaccess重写会影响html图像源的url

I am trying to redirect a link like www.mywebsite.com/phpfile/uservalue/ to www.mywebsite.com/phpfile.php?param=uservalue

So my .htaccess file is

Options -Indexes
Options +FollowSymLinks  
RewriteEngine On  
RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  
RewriteRule ^phpfile/(\w*)$ ./phpfile.php?param=$1  

The redirect works well. Now I have a problem. My phpfile.php contains the following html code among other things

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<img src="logo.png">
</body>
</html>

Now if I enter www.mywebsite.com/phpfile.php?param=uservalue in the browser, the image loads. But if I enter www.mywebsite.com/phpfile/uservalue/ the image does not load.

On inspecting the element, I found that, the php was trying to load http://mywebsite.com/phpfile/logo.png when the image is actually in http://mywebsite.com/logo.png

How do I prevent the extra 'phpfile' folder being added to the image url?

  • 写回答

1条回答 默认 最新

  • doufocheng6233 2012-10-29 14:30
    关注

    You can solve this using relative url instead of <img src="logo.png"/> use <img src="www.mywebsite.com/logo.png"/>" and you will have no problem in the future.

    or if you want can use base element this way <base href="http://www.mywebsite.com"> and you can use it the same way you are using it <img src="logo.png"/>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?