0

I am using Yeoman package manager to create an angular web application. this is my main controller:

 'use strict';
angular
 .module('resFourApp', [
 'ngCookies',
 'ngResource',
 'ngSanitize',
 'ngRoute',
 ])
 .config(function ($routeProvider, $locationProvider) {
 $routeProvider
 .when('/', {
 templateUrl: 'views/main.html',
 controller: 'MainCtrl'
 })
 .when('/about', {
 templateUrl: 'views/about.html',
 controller: 'AboutCtrl'
 })
 .when('/contact', {
 templateUrl: 'views/contact.html',
 controller: 'ContactCtrl'
 })
 .otherwise({ redirectTo: '/' });
 // use the HTML5 History API
 // use the HTML5 History API
 $locationProvider.html5Mode(true);
 });

which works fine if I access the app from the base directory but if I access it from the url and go to www.base.com/route I get a 404 error. Which I understand is because Angular is a client side app so there is nothing on the server to handle these requests. I have read a lot online about having to reroute with server or mod rewrites with apache, but I still have not gotten it working.

Things I have tried

Apache rewrite rules not being applied for angularjs

https://groups.google.com/forum/#!msg/angular/GmNiNVyvonk/mmffPbIcnRoJ

my .htaccess for apache web server:

 # BEGIN angularJS
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*) /index.html/#/1ドル 
</IfModule>
# END angularJS
asked Jun 28, 2014 at 16:52

1 Answer 1

2

I've tried a few things with rewriting and couldn't get it to work but found a workable solution using redirection and the NE flag

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ #/1ドル [NC,R,NE]

There seems to be quite a few other interesting links from this SO answer regarding the hash/ URL fragment: https://stackoverflow.com/a/15135130

answered Jun 29, 2014 at 3:35
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.