title: Deploy Angular 2 to Apache Server
body: <p>I want to deploy an Angular 2 application on an Apache server. I've read various guides like <a href="https://github.com/mgechev/angular-seed/wiki/Deploying-prod-build-to-Apache-2" rel="nofollow noreferrer">this</a> and <a href="https://github.com/angular/angular/issues/11884" rel="nofollow noreferrer">this</a> but none of them is working. I have <code>npm</code> and <code>ng</code> installed on the server.</p>
  <p>In a nutshell, here's what I did:</p>
  <ol>
  <li>Cloned complete project repository on my server.</li>
  <li>Installed dependencies using <code>npm install</code>.</li>
  <li>Used <code>ng build --prod</code> command and it created a <code>dist</code> directory.</li>
  <li>Changed <code>apache</code> root to <code>/var/www/html/dist</code> directory.</li>
  <li>Enabled <code>mod_rewrite</code>, restarted <code>apache</code> and added this <code>.htaccess</code> in my <code>dist</code> directory.</li>
  </ol>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
  &lt;/IfModule&gt;
  </code></pre>
  <p>But only my home page <code>domain.com</code> works, other pages like <code>domain.com/login</code>, <code>domain.com/register</code> etc. throw 404 error. Even <code>domain.com/index.html/login</code> doesn't work.</p>
  <p>The application works fine on my local system where I'm developing it using <code>ng serve</code>. What am i missing?</p>