【问题标题】:Make domain folder act as root使域文件夹充当根
【发布时间】:2019-03-17 19:05:33
【问题描述】:

我有一个域,例如 https://test.com 这个域在https://test.com/system 中包含一个完整项目

问题:

每当我写 <link ref="stylesheets" href="/style/main.css"> 时,它都会在域根目录中搜索,而不是在项目所在的 system 目录中。

我试图做的事情:

我已尝试将所有路径编辑为等于 href="style/main.css" 而不是 href="/style/main.css"

此解决方案有效,但我不会每次进入生产模式时都这样做。

我想做什么:

我知道有一个使用.htaccess 的解决方案,但我不知道怎么写..

【问题讨论】:

    标签: html .htaccess server subdomain hosting


    【解决方案1】:

    试试

    <link ref="stylesheets" href="./system/style/main.css">

    <link ref="stylesheets" href="../system/style/main.css">.

    如果还是不行,就用三个点。

    <link ref="stylesheets" href=".../system/style/main.css">.

    它对我有用。


    使用.htaccess将子目录设置为根目录

    视情况而定,对于某些托管服务,您只需要添加此行:

    RewriteBase /system

    如果这不适合你,试试这个:

    RewriteEngine On
    # Map http://www.example.com to /system.
    RewriteRule ^$ /system/ [L]
    # Map http://www.example.com/x to /system/x unless there is a x in the web root.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/system/
    RewriteRule ^(.*)$ /system/$1
    # Add trailing slash to directories within system
    # This does not expose the internal URL.
    RewriteCond %{SCRIPT_FILENAME} -d
    RewriteRule ^system/(.*[^/])$ http://www.example.com/$1/ [R=301]
    

    【讨论】:

    • 我使用过href="system/style/main.css",它对我有用,但.htaccess 中有一种方法可以将此子目录设置为root .. 因为我不想更改我所有的css、js、图像和其他路径
    • 检查所做的更改。
    猜你喜欢
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    相关资源
    最近更新 更多