【问题标题】:.htaccess Rewrite rule cause css, js stop working.htaccess 重写规则导致 css、js 停止工作
【发布时间】:2016-09-23 04:14:45
【问题描述】:

我知道这是常见问题,但我在 SO 找不到解决我的问题的方法

htaccess 是

RewriteEngine On
RewriteBase /app/
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

并且 index.php 只包含一个 require 到 index.html 存在的 html。

我尝试在我的 css 相对路径中使用 /,但没有任何改变。我也使用了<base href="/">,但也没有任何改变。指令

RewriteRule ^(.+?\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [NC,L]

也不要解决问题。

更新。问题解决了

我检查了显示错误variable ${REQUEST_FILENAME} is not defined 的错误日志。所以将$ 更改为% .htaccess 解决问题

【问题讨论】:

  • 我查看了 access.log,但找不到有趣的东西。
  • 在我的最后 8 个日志(我的最后一个请求)中显示 404 错误

标签: php html css .htaccess mod-rewrite


【解决方案1】:

请注意,在 Apache httpd 2.2.16 及更高版本中,有一个新指令正是为这种情况而创建的。它称为 FallbackResource。见http://httpd.apache.org/docs/current/mod/mod_dir.html#fallbackresource

在你的情况下,你想要:

FallbackResource /app/index.php

【讨论】:

    【解决方案2】:

    确保页面中的所有链接都已完全定义

    <head>
      <link href="http://yoursite.com/style.css" rel="stylesheet" type="text/css">
      <script src="http://yoursite.com/script.js"></script>
      </head>

    如果您只有&lt;link href="style.css" rel="stylesheet" type="text/css"&gt;,则在使用.htaccess 后将无法使用。

    【讨论】:

    • 不会帮助我获得资源的绝对路径,因为我正在开发环境中进行开发,当应用程序上线时,所有链接都必须更改......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 2019-09-16
    • 2013-06-25
    • 1970-01-01
    • 2015-12-25
    相关资源
    最近更新 更多