使域文件夹充当根目录

时间:2018-10-12 14:12:03

标签: html .htaccess server subdomain hosting

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

  

问题:

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

  

我试图做的事情:

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

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

  

我正在尝试做的事情:

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

1 个答案:

答案 0 :(得分:0)

尝试

  

<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]
相关问题