0

I am getting a strange behaviour while trying to setup an apache2 virtual host with mod_rewrite for an angular2 app.

I am not using HashLocationStrategy, http://host.tld/#page but the default LocationStrategy http://host.tld/page, which obviously needs mod_rewrite enabled and setup correctly.

The local url I am trying to reach is http://calendar.atlas.local/ My console shows some (not all) requests to http://www.calendar.atlas.local/ while trying to load some of the components, which is weird.

Here is my .htaccess

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]

    RewriteRule ^(.*) /index.html [NC,L]
</IfModule>

Here is my .conf for apache2 on OSX El Capitan

<VirtualHost *:80>
        DocumentRoot "/Library/WebServer/Dev/NG-CAL/"
        ServerName calendar.atlas.local
        ErrorLog "/private/var/log/apache2/calendar.local-error_log"
        CustomLog "/private/var/log/apache2/calendar.local-access_log" common

        <Directory "/Library/WebServer/Dev/NG-CAL/">
            AllowOverride All
            Require all granted

        </Directory>
</VirtualHost>

I have no idea where the "www" comes from.

pop
  • 101
  • 2
  • If you are seeing `www` in the _requests_, isn't that some kind of config issue with your Angular2 app? – MrWhite Jan 13 '17 at 11:15
  • The weird part is that *most* of the requests go to http://calendar... but some of them (two, to be precise) are loaded for the second time *and* www will be requested. All paths within angular app are relative. – pop Jan 13 '17 at 11:59
  • Current config shows nothing that mentions a www, but usually requests come from a "client", or some link or reference makes the client request that. Extra note: you seem you don't need to use .htaccess and/or mod_rewrite at all. `DirectoryIndex index.html` and `FallbackResource /index.html` in VirtualHost seem would simplify your configuration a lot and work perfectly for you. – Daniel Ferradal Jan 13 '17 at 12:45
  • Didn't help, unfortunately. :/ I guess, I will have to build and publish the app by way of AngularCLI or gulp and hope, that the issues will go away. Thanks. – pop Jan 13 '17 at 14:40

0 Answers0