1

I have tried this answer and can confirm that mod_rewrite is enabled on my hosting

And I have tried the following .htaccess configurations from various answers and sites but none helped.I'm not able to debug where the problem is.

From the official site:

RewriteEngine On
    # If an existing asset or directory is requested go to it as it is
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    RewriteRule ^ - [L]
    # If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

From some gist

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

And many others but all are giving 404 errors. Any way to debug it. I'm using ng build --prod to make a dist then hosting on dev.example.com and trying to access dev.example.com/home which is available when accessed from dev.example.com Could it be due to sub domain?

Black Mamba
  • 13,632
  • 6
  • 82
  • 105

3 Answers3

0

Try this configuration:

 RewriteEngine on
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    # Rewrite everything else to index.html
    RewriteRule ^ index.html [L]
Ashish Ranjan
  • 12,760
  • 5
  • 27
  • 51
  • Ahh, No success :( – Black Mamba May 06 '18 at 18:15
  • @BlackMamba: you are testing under `.htaccess` right? you have the `AllowOverride All` in your `vHost`? – Ashish Ranjan May 06 '18 at 18:18
  • Where is it I'm on a shared hosting so I have limited access.I think it is enabled by default as the rest redirects are working fine. – Black Mamba May 06 '18 at 18:22
  • Okay, if you are on a shared hosting then they must have added the config to override. You can check by doing something like: `RewriteRule ^(.*)$ $1/haha [NC, L]` just after `RewriteEngine On`, see if all your URLs are redirected to URL appended with `haha`? And I also wanted to know, if this is just happening in `production build` but `development` build works fine? – Ashish Ranjan May 06 '18 at 18:30
  • Giving 500 error in response. Haven't checked with a development build yet.I think this won't help as it is a server side issue – Black Mamba May 06 '18 at 18:37
  • Okay, do one thing, replicate this on your local first.. create a virtual host with sever name : "dev.example.com" see if your config works in your machine.. – Ashish Ranjan May 06 '18 at 18:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170485/discussion-between-black-mamba-and-ashish-ranjan). – Black Mamba May 06 '18 at 18:43
0

I confirm that it wasn't a subdomain issue. After trying a ton of .htacess files I was able to find RewriteBase, add it to your base path like let's suppose your base path is /dev/ Add Rewritebase /dev/ and don't forget to add Options Indexes FollowSymLinks .

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

If you are facing problem with basepath please see this question Angular 2 routing and direct access to a specific route : how to configure Apache? and this answer https://stackoverflow.com/a/36590784/6517383 Surely they will fix your deployment related issue on apache server

Black Mamba
  • 13,632
  • 6
  • 82
  • 105
0

I was missing httpd.conf, AllowOverride All over my directory

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
bukart
  • 4,906
  • 2
  • 21
  • 40
6uz
  • 1
  • 1