Setup.htaccess从主子文件夹读取静态文件夹,而不是public_html



我决定将我的react应用程序文件更改为位于子文件夹public_html/main/中——出于git自动化的原因——,然后我还对.htaccess文件进行了一些更改,以便它可以读取主文件夹。

现在,读取main/index.html工作得很好,尽管.htaccess没有在main中检测到static/,而是在public_html/中寻找它(我知道它,因为当我在那里放置静态时它工作了(。我需要以某种方式将这个点文件更改为子文件夹中的静态文件。

我的服务器上有下一个文件夹树结构:

public_html/
.htaccess
main/
index.html
static/
css/
js/
media/

.htaccess看起来像:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$
RewriteCond %{REQUEST_URI} !^/main/
RewriteRule ^(.*)$ /main/$1
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$
</IfModule>

当我知道在根文件夹和子文件夹中都可以有一个.htaccess文件时,我设法解决了这个问题。当子文件夹中的点文件将覆盖其他.htaccess时。

所以我配置根(public_html/(.htaccess如下:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$
RewriteCond %{REQUEST_URI} !^/main/
RewriteRule ^(.*)$ /main/$1
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$

在位置为public_html/main/的子文件夹中,.htaccess结束像这样:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

实际工作和阅读所需的文件。

最新更新