doutui7955 2012-08-18 21:10
浏览 95
已采纳

这个mod_rewrite规则如何导致我的任何文件都无法加载?

The following mod_rewrite rule is causing my website to behave odd I type localhost/signin/.

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^signin/?$ access.php [NC,L]

It causes all of the attached files (images, css, php, js) with relative links not to load? However when I type localhost/signin all the attached files with load like nothing is wrong. I think this happens because /signin/ is treated like a directory and all relative links will look into an non-existence directory for all the attached files.

Edit: I figured out a solution but it involves muddying up my markup which is not what I want. Look at my answer below and you'll see.

However, I want these attached files to be ignored by the rewrite rules.

  • 写回答

3条回答 默认 最新

  • dongxiatuo9827 2012-08-18 21:46
    关注

    The problem

    The problem you have is (after clarification) not related to the use of rewrite rules. Please edit your question to accurately represent your problem.

    Almost certainly because you have references such as:

    <link rel="stylesheet" type="text/css" href="css/foo.css">
    <script src="js/foo.js">
    

    which means the route used to find the css/js files is dependent on the directory (virtual or real) of the current request.

    If the current request is /foo, the request is in the root dir. As such, the following urls would be requested:

    /css/foo.css
    /js/foo.js
    

    If, however the current request is /foo/, the request is in the dir /foo/. As such, the following urs would be requested:

    /foo/css/foo.css
    /foo/js/foo.js
    

    Use absolute urls

    The way to avoid this is simply to use absolute urls in your link/script tags:

    <link rel="stylesheet" type="text/css" href="/css/foo.css">
    <script src="/js/foo.js">
    

    That way, irrespective of the current url - the exact url in the link and script tag is used.

    Base tag - be careful

    You can as you note in your own answer use the base tag - but it's much more obvious to not rely upon it. There are also problems with some browsers e.g. converting "#" into an a request for "/#" which is another reason to ignore the base tag's existence.

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

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作