Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to add htaccess file in angular 4 cli project to add rewrite rules?

I have completed angular project. now i want to change some url format force fully using htaccess file.so where should i put htaccess file? I have tried everywhere like belows path:

/opt/lampp/htdocs/GreatColoradoHomes
/opt/lampp/htdocs/GreatColoradoHomes/src
/opt/lampp/htdocs/GreatColoradoHomes/src/app
like image 361
Gauravbhai Daxini Avatar asked Dec 18 '17 11:12

Gauravbhai Daxini


Video Answer


2 Answers

there is answer in github issue

Put .htaccess in src folder (final path for is src/.htaccess)

Add it to angular-cli.json in the assets array (like favicon.ico).

Have something similar to this:
"assets": [ "assets", "assets/images/favicon.ico", ".htaccess" ],

like image 176
voznik Avatar answered Nov 10 '22 14:11

voznik


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.

enter image description here

With the above settings, when you run your build, you'll get the .htaccess inside the dist.

enter image description here

like image 34
Anjana Silva Avatar answered Nov 10 '22 14:11

Anjana Silva