I tried to use the Homestead with my Angular project, and when I press refresh in browser on an URI (what is acually doesn't exists) the RewriteRule doesn't catch the request and isn't redirect to the index.html file where the Angular can handle the URI.

Here is my .htaccess file:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]

I always get No input file specified. message if refresh on a route. On the main path (www.example.test/) the index.html file is loading well.

What is the correct .htaccess configuration to this case? Or if not the .htaccess is the problem where can I check other settings?

2 Answers

netdjw On Best Solutions

I found the problem.

My Homestead run with Nginx http server, so the .htaccess file is ignored.

So I need to edit the config file under the /etc/nginx/sites-enabled/mydomain.test file, update with this:

location / {
    try_files $uri $uri/ /index.php?$query_string;

    // this is what I added:
    if (!-e $request_filename){
        rewrite ^(.*)$ /index.html break;

This solved the problem.

Pawan Jangid On

Try this

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