Home AngularJS HTML5 mode with UI Router on apache
Reply: 0

AngularJS HTML5 mode with UI Router on apache

user2181
1#
user2181 Published in June 19, 2018, 6:27 pm

I had turned on the html 5 mode on my angular(1.5.8) app a few days back with this code:

$locationProvider.html5Mode({enabled:true,requireBase:true}).hashPrefix('!');

Later I read configuring apache server for html5 mode with ui-router.

After doing these settings, I am facing 2 problems:

  1. Browser reload, redirects to home page for every deep nested app link.
  2. Any link coming from outside(via email) always redirects to the homepage.

I have played with

  1. mod_rewrite as-in using <Directory>, FallbackResource on apache.
  2. changing paths to assets in the index.html (using relative URI and full qualified URI)
  3. adding/removing the base HTML tag. (trying options like '/', '<sitename>')

But I am yet to overcome these problems.

Here is the detailed setup on my localhost:

  1. I am deploying to apache via Virtual Host(and not .htaccess).
  2. My deployment directory is /Users/<name>/Sites/<sitename> (I am on mac OS)
  3. My index.html in-parts is as follows:

        <head>
          <base href="/">
          <!-- SPELLS 1-->
            <script src="/js/jquery.min.js"></script>
            <script src="/js/bootstrap.min.js"></script>
            <script src="/js/angular.min.js"></script>
            <!-- more scripts / css et al -->
        </head>
    
  4. My Apache(2.4.28) config is as follows:

        <VirtualHost *:80>
        ServerName <servername>
        DocumentRoot "/Users/<name>/Sites/<sitename>"
        #LogLevel debug
        LogLevel debug rewrite:trace6
        RewriteEngine on
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
        RewriteRule ^ - [L]
        RewriteRule ^ index.html [L]
    
        Options Indexes FollowSymLinks
        Require all granted
    
        </VirtualHost>
    

Can anyone help me with the exact setup?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.387134 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO