Skip to content

Instantly share code, notes, and snippets.

@julianpoemp
Last active August 8, 2024 09:32
Show Gist options
  • Save julianpoemp/bcf277cb56d2420cc53ec630a04a3566 to your computer and use it in GitHub Desktop.
Save julianpoemp/bcf277cb56d2420cc53ec630a04a3566 to your computer and use it in GitHub Desktop.
Optimal .htaccess configuration for Angular 15, Angular 14, Angular 13, Angular 12, Angular 11, Angular 10, Angular 9, Angular 8, Angular 7, Angular 6, Angular 5 (and older) app in production incl. fix for the angular browser caching issue.

New generator

I created a new htaccess generator for angular apps that makes it easier for you to create the optimal htaccess file: https://julianpoemp.github.io/ngx-htaccess-generator/

The goal of this generator is to create the optimal .htaccess file for Angular apps easily. By default the generator creates an .htaccess file that solves the route redirection issue. To make it easier for you I created a kind of interview mode with some questions. As an additional feature the generator supports adding exclusions for example if you have installed a blog in a subdirectory of your web application and more!

The generator 😁: https://julianpoemp.github.io/ngx-htaccess-generator/

The project: https://github.com/julianpoemp/ngx-htaccess-generator

Place for issues and bug reports: https://github.com/julianpoemp/ngx-htaccess-generator/issues

Questions and discussion

If you have questions you can comment below. Please report bugs here.

@julianpoemp
Copy link
Author

@NavneetVaid nginx is not supported. If you are facing the reloading issue, use HashLocationStrategy: https://v17.angular.io/api/common/HashLocationStrategy

@NavneetVaid
Copy link

I dont want to use hashLocationStrategy, i want to have my url working without a #

@julianpoemp
Copy link
Author

@NavneetVaid you need to change your nginx config:
https://stackoverflow.com/a/47929996/6303600

If you only have access to your app's index.html you can try option 2 from this stackoverflow post:
https://stackoverflow.com/a/53993744/6303600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment