Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Angular html5Mode apache working in a subdirectory /app using ngRoute
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /app/index.html [NC,L]
</IfModule>
var app = angular.module('myApp', ['ngRoute'])
.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/list',
{
templateUrl: 'templates/list.html',
controller: 'ListController'
});
$routeProvider.when('/new',
{
templateUrl: 'templates/new.html',
controller: 'EditController'
});
//Default URL
$routeProvider.otherwise({redirectTo:'list'});
//html5Mode don't need /app/#/ anymore, just /app/
$locationProvider.html5Mode(true).hashPrefix('!'); //the hashPrefix is for SEO
})
;
<!doctype html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>List</title>
<base href="/app/"><!-- Make sure the base is above your stylesheet -->
<meta name="fragment" content="!" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" href="css/app.css" />
</head>
<body>
<ng-view></ng-view>
<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-route.min.js"></script>
<script src="js/controllers/ListController.js"></script>
<script src="js/controllers/EditController.js"></script>
</body>
</html>
@lenichols

This comment has been minimized.

Copy link

lenichols commented Mar 24, 2016

Thanks for this... i was looking for dets on how to write my .htaccess file to work with angulars ugly hashed URLS.

@johhansantana

This comment has been minimized.

Copy link

johhansantana commented Jun 30, 2016

awesome, thanks!

@vinnycrazzy

This comment has been minimized.

Copy link

vinnycrazzy commented Oct 10, 2016

Suuuper Awersomeeeee meaaan!

@ethanmay

This comment has been minimized.

Copy link

ethanmay commented Dec 20, 2016

This is great! Thank you!

@royanon

This comment has been minimized.

Copy link

royanon commented Apr 19, 2018

sweet!

@amazejeewan

This comment has been minimized.

Copy link

amazejeewan commented Jun 13, 2018

Thank you it worked for me also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.