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
2
Answers
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: