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条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大