I am using multiple angular projects on single server,
This is my folder structure of my projects
Root: Project-1
Root/test : Project2
Root/test/new : project3
Here is the htaccess code, that I am using. but subdirectory projects not working some times
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
The issue is, when I am trying to access the second project using this url, www.domain.com/test
, its redirecting to root
folder, that is project1
. I think it’s checking project1 routing, when iIaccess project2
How can I fix the issue.
2
Answers
I have a similar project structure and the below .htaccess works for me.
See if it works.
Look my friend. What you want to do is easily solved.
There are 2 important places to make your app start url clear to Angular:
1 – In the index.html file
2 – In the .htaccess file on the server
The changes that you must make for the "Project2" are the following.
1 – You look within your code in index.html of your Angular app for the following line of code:
You will modify it by putting the following
2 – You create the .htacces file in the root of the Root/test directory with the following content:
Note that in the last line
RewriteRule ^ /index.html
and change it to your path to the index.html file of your compilation, leaving it as follows:That is all.
Now you will do the same procedure for Project3 and you will see how everything works perfectly. Ej:
In index.html
<base href = "/test/new/" />
and in .htaccess
RewriteRule ^ /test/new/index.html