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.

    <base href="/">

2) Angularjs

Add html5Mode inside your angularjs config file.

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

3) .htaccess url rewrite

Put this inside your .htaccess file.

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

About Sanju

I’m Sanjunath.S from Mumbai, India. I like web technologies, traveling & history. I have 11+ years of experience in web technologies like HTML 5, CSS 3, JavaScript, Bootstrap, and PHP.

Pay with PayPal
Translate »