Rohit Jindal Rohit Jindal - 18 days ago 6x
AngularJS Question

"base href" adds directory path in routing urls using ui-router

Summary :

When using

<base href="/prod/public/" />
, it adds the directory path in routing urls

My angular app is hosted in the

in my

<base href="/prod/public/" />

my routes are like :

.state('home', {
url: '/home',
templateUrl: function($stateParams) {
var path = 'app/users/views/home.html';
return path;
controller: 'HomeCtrl'

directory :

RewriteEngine On
Options -Indexes
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ public/index.html [L]

and here is how I reference the state in the template :

<a ui-sref='home'>Go to home</a>

When click on this link it redirect to this url :

Requirement :

url should be
instead of


The <base href="/prod/public/"/> in angular routing is not to set the document root / Mask the url but to rather prepend urls with the defined url in HTML5 mode.

When you define a route eg /home angular will correctly set the URL as /prod/public/home. If you wish to have your urls without that folder structure then you will then need to put the files in the root directory (especially in the case of shared hosting) or alter the Nginix / Apache Document root setting to point to the correct path. You can then set the which will make your urls read as /home etc