如何在子文件夹中使用索引文件托管我的网站?
我想从/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
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是将您的项目放在
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 yoursrc
folder inDocumentRoot
.If you want your project to be the top level (as in your example,
http://example.com/
), then you can directly setDocumentRoot
to yoursrc
folder, or replace theDocumentRoot
folder with a softlink as described above.这自然会重写所有内容。要重写根本的请求,只有然后您需要与
^$
匹配。例如:
This naturally rewrites everything. To rewrite requests for the root only then you need to match against
^$
instead.For example: