doudieheng5322 2011-02-21 11:54
浏览 28
已采纳

mod_rewrite更改当前目录

I have a php file that loads an article from a db based on the given variables. There is also an .htacces file in the root of the site. I used this in the htaccess to redirect

RewriteRule ^articles/([a-zA-Z0-9-_\s]+).html$ template/index.php?action=viewarticle&alias=$1

after redirecting, the page shows fine but the html in the page goes wrong, for example:

media/2011/02/21/logos.jpg turns in to articles/media/2011/02/21/logos.jpg

This happens because the htacces is redirecting. Is there anyway to do this redirect while keeping the root dir unchanged?

  • 写回答

3条回答 默认 最新

  • dongshuogai2343 2011-02-21 11:58
    关注

    This happens coz the htacces is redirecting.

    No, this happens because the browser thinks that

    example.com/articles/my_article.html
    

    is a resource in the /articles sub-directory, and treats all relative URLs as relative to /articles.

    There is no way to change that behaviour.

    You will need to start using absolute image references, or relative image references that consider the additional directory:

    <img src="/media/2011/02/21/logos.jpg">      <------ recommended
    <img src="../media/2011/02/21/logos.jpg">
    

    you could also use <base> as suggested by @Boris but absolute paths (or full URLs) are a vastly cleaner solution to the problem in my opinion.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效