Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vhosts conf for single page app

I have an angular app that I'm serving locally using apache. My vhosts.conf is:

<VirtualHost *:80>
  ServerName my.app.com
  DirectoryIndex index.html
  DocumentRoot /export/www/app
  <Directory "/export/www/app">
    order allow,deny
    allow from all

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.html/$1 [L]
  </Directory>
</VirtualHost>

If I go to the root of the app everything loads fine. I do some navigation within the app which brings me to my.app.com/some/location and still no problem.

However if I reload the page at this point I get a 404 error. To get back to the point I want I need to either go back to the root and navigate via the app again or else search by url my.app.com/#/some/location

Is there something that I can do with a rewrite rule so that I don't need the hash to reload the route? I tried to edit my existing rule to:

RewriteRule ^(.*)$ index.html/#/$1 [L]

Any ideas greatly appreciated C

like image 833
Cathal Avatar asked Jul 31 '15 11:07

Cathal


People also ask

What is ServerName in httpd conf?

This option corresponds to the ServerName directive in httpd. conf . The ServerName directive sets the hostname of the Web server. It is used when creating redirection URLs.


1 Answers

The issue was that I was using a newer version of apache where the config rules have changed. My updated vhosts now reads

<VirtualHost *:80>
  ServerName my.app.com
  DirectoryIndex index.html
  DocumentRoot /export/www/app
  <Directory "/export/www/app">
    order allow,deny
    allow from all

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) /index.html [NC,L]
  </Directory>
</VirtualHost>
like image 186
Cathal Avatar answered Sep 16 '22 17:09

Cathal