Yuschick Yuschick - 2 months ago 10
Apache Configuration Question

htaccess - Redirect All but Sub-Directory (Ember js)

I am running my main website with Ember and because of that have my htaccess file set up to redirect all requests to my index page for routing.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]


However, I have since added a sub-directory called
/horror
that is also running on Ember. Any request made to
domain.com/horror
I want to have redirect to
/horror/index.html
again, for proper routing.

Currently, when I access
domain.com/horror
the page runs. But if I try going directly to
domain.com/horror/1
I am redirected to my main domain's 404 page and not to the correct
/horror/
route. I need this
/horror
directory to function as a standalone site - accessing its own CSS, Js, and images without conflicting with the main domain's Ember router.

How can I configure my .htaccess file to handle this?

Answer

You can have a separate rule for handling /horror/:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/horror/index\.html$ [NC]
RewriteRule ^horror(/.*)?$ horror/index.html [L,NC]    

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]