user3466163
user3466163

Reputation: 37

Redirect all requests to specific directory without changing URL .htaccess (Deploying Angular project)

I have an Angular project and I want to deploy it on a specific folder (not root) so something like this : http://localhost/folder/index.html So i need to redirect all requests on this path without changing URL.

The following works fine when the index.html is at root (so, http://localhost/index.html) :

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

So I tried to change this code like this to work with my project :

RewriteRule ^ /folder/index.html

I works fine with this request : http://localhost/folder/abcd but not with http://localhost/folder/abcd/efgh, http://localhost/folder/abcd/efgh/.../..../.....

Thank you for your help!

Upvotes: 2

Views: 517

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133518

Could you please place your .htaccess file inside folder named folder. Please make sure you clear your browser cache before testing your URLs.

As mentioned in the comments: In the header of your webpage add this <base href="/"> so that your relative links can load from the correct location

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

Upvotes: 2

Related Questions