如何在子文件夹中使用索引文件托管我的网站?

发布于 2025-02-06 03:58:31 字数 703 浏览 3 评论 0原文

我想从/src/index.html
托管我的网站 因此,如果您访问我的网站https://example.com,您将看到/src/index.html的内容(不添加/src/ index.html to url)

这是我的文件结构

//i.sstatic.net/qopqc.png“ alt =“文件结构”>

我尝试在.htaccess文件中添加以下内容:

RewriteRule ^ src/index.html

该文件正确重定向,但也将所有路径重定向到任何其他文件(例如样式) .css)至src/index.html使其无法使用。

以下内容会起作用,但它会将URL更改为example.com/src/index.html,而我希望它留在example.com.com

Redirect 301 /index.html /src/index.html

I would like to host my website from /src/index.html
So if you visit my website at https://example.com, you will see the contents of /src/index.html (without adding /src/index.html to the url)

This is currently my file structure

file structure

I tried adding the following in my .htaccess file:

RewriteRule ^ src/index.html

That redirects correctly but also redirects all paths linking to any other files (like style.css) to src/index.html making them unusable.

Something like the following would work but it would change the url to example.com/src/index.html while I would like it to stay at example.com:

Redirect 301 /index.html /src/index.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扎心 2025-02-13 03:58:34

最简单的方法是将您的项目放在documentroot之外的其他地方,然后将软链接(ln -s)在<<<代码> document root 。

如果您希望您的项目成为最高级别(如示例中,http://example.com/),那么您可以将docuct> docuct> docuctroot直接设置为src文件夹,或用上述软链接替换docuctroot文件夹。

The easiest way is to put your project elsewhere, outside of DocumentRoot, and make a softlink (ln -s) to your src folder in DocumentRoot.

If you want your project to be the top level (as in your example, http://example.com/), then you can directly set DocumentRoot to your src folder, or replace the DocumentRoot folder with a softlink as described above.

一袭白衣梦中忆 2025-02-13 03:58:33
 重写 ^ src/index.html
 

这自然会重写所有内容。要重写根本的请求,只有然后您需要与^$匹配。

例如:

 RewriteRule ^$ src/index.html [L]
RewriteRule ^ src/index.html

This naturally rewrites everything. To rewrite requests for the root only then you need to match against ^$ instead.

For example:

 RewriteRule ^$ src/index.html [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文