Home -› Angular Js -›

Category Archives: Angular Js

19 Dec

Remove hash from AngularJs url

Remove hash from AngularJs url

Rewrite your AngularJs app url from http://domain.com/#/path/ to http://domain.com/path/

There are few things to set up for remove hash from AngularJs url. So your link in the browser will look like http://domain.com/path/ and these are your base href + angularjs config + .htaccess url rewrite.

1) Base href

Set the base href in HTML file.

<html>
  <head>
    <base href="/">
  </head>
</html>

2) Angularjs

Add html5Mode inside your angularjs config file.

app.config(function ($routeProvider,$locationProvider) {
$routeProvider
  .when('/', {
	templateUrl: 'home-page.html',
	controller : 'appController'
	});
$locationProvider.html5Mode(true);
});

3) .htaccess url rewrite

Put this inside your .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]