Clowning
Clowning

Reputation: 179

Angular2 apache rewriting

I'm using Angular2 to build a web mobile application, when i build my project and run it on local, everything works perfectly but when i push it into our production system i have problem, i think it's about Apache Rewriting !

My url in local http://127.0.0.1/ My url un prod http://domain.tld/mobile/

When my application is on production, it doesn't load any link like css or js ... so my application doesn't work !

My .htaccess look like this :

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

So to resolve my issue i think i need to edit my htaccess but how can i say to it to use /mobile and / but if i put only /mobile my application will do not work on local..

So if you have any idea ?

Thanks :)

Upvotes: 0

Views: 594

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71961

You can either try to change your local development to serve from a subfolder named mobile and place your project in there. You need to change your base href tag inside your index.html to:

<base href="/">

Another option could be to only change the base href inside the index.html of your production build.

If you are using the angular-cli, it has an option to edit the base href during the build process:

ng build --base-href=mobile

Upvotes: 2

Related Questions