skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search