【问题标题】:assets relative to root, but html files are in subfolder资产相对于根目录,但 html 文件位于子文件夹中
【发布时间】:2021-07-04 13:14:33
【问题描述】:

我今天收到了 675 个 html 文件。

文件夹结构如下:

 - index.html
 - /assets/
 - /pages/

pages/ 文件夹中,我有 675 个 html 文件。在他们每个人中,我都有与根文件夹相关的所有资产,如下所示:

<link rel="stylesheet" href="/assets/css/main.css">

我已经把所有东西都上传到我的演示服务器了,网址是这样的:

https://example.com/CLIENT/rebrand/

index.html 页面包含pages 文件夹中的 675 个 html 文件的列表。

你可以想象,当我点击其中一个时,我得到了页面,但是没有加载图像、js 和 css。

有没有办法通过 .htaccess 来指示服务器解释

<link rel="stylesheet" href="/assets/css/main.css">

作为

<link rel="stylesheet" href="/CLIENT/rebrand/assets/css/main.css">

我想避免在这么多文件中进行大量搜索和替换,因为破坏某些东西的风险很高。

你们对更清洁的解决方案有任何提示吗?谢谢

【问题讨论】:

    标签: .htaccess mod-rewrite path xampp lamp


    【解决方案1】:

    您可以在 .htaccess 顶部使用此重定向规则进行此重定向:

    RewriteEngine On
    
    RewriteRule ^assets/.+$ /CLIENT/rebrand/$0 [L,NC,R=301]
    
    # other rules appear below this line
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      相关资源
      最近更新 更多