使域文件夹充当根

Make domain folder act as root

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

Problem:

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

What I have tried to do:

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

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

What I am trying to do:

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

尝试

<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/
# Add trailing slash to directories within system
# This does not expose the internal URL.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^system/(.*[^/])$ http://www.example.com// [R=301]