douhuai2861 2012-07-10 10:14
浏览 42
已采纳

为什么我的php文件在使用RewriteRule时无法找到外部文件(image,css ...)?

I am using following RewriteRules :

RewriteRule ^([a-zA-Z0-9]+)$ page.php?p=$1
RewriteRule ^e/([a-zA-Z0-9]+)$ edit.php?p=$1

The first one works fine : when typing mysite.com/id it loads mysite.com/page.php?p=id on server side.

The second one is working as well : when I type mysite.com/e/id it loads mysite.com/edit.php?p=id (as expected). But in that case edit.php can't loacte any external files like my css file.

<link rel="stylesheet" type="text/css" href="style.css" />

When doing either :

<link rel="stylesheet" type="text/css" href="../style.css" />

Or simply removing the direcory in the RewriteRule like :

RewriteRule ^e_([a-zA-Z0-9]+)$ edit.php?p=$1

it fixes that problem.

Now I don't understand why my edit.php is unable to locate external files even thought it loads on the correct path on server-side (mysite.com/) and not like the url displays in an extra directory (in this case mysite.com/e/ ).

  • 写回答

2条回答 默认 最新

  • dousui6488 2012-07-10 10:17
    关注

    You can use a base url for all the site's paths, like this:

    <base href="http://yoursite.com/blog/" />
    

    or

    <base href="/blog/" />
    

    And then writing relative paths from the base's:

    <a href="rule/foo/">...</a>
    

    Plus, you have to be extra careful with those "accept all" patterns, as they may conflict with the stylesheets, images and the rest of media if not used properly. Either appending an extension to the patterns or excluding media could be possible fixes.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度