where to add htaccess file in angular 4 cli project to add rewrite rules?
You can also copy files to dist
folder after build by defining your build commands in package.json
on key scripts
e.g.
"buildProd": "ng build --prod && cp ./.htaccess ./dist/project-name/.htaccess",
copy file .htaccess
to main projet folder (not src) and run build command by npm run buildProd
to create dist
.
This approach not introduce server files to angular build step (it do it "outside").
By having .htaccess
outside the src
, you'll most likely to get the following error,
An unhandled exception occurred: The .htaccess asset path must start with the project source root.
The corrected approach is this,
"assets": [ "src/favicon.ico", "src/assets", "src/.htaccess"],...
Make sure to put your .htaccess
file under src
.
With the above settings, when you run your build
, you'll get the .htaccess
inside the dist
.