Summary :
When using <base href="/prod/public/" />
, it adds the directory path in routing urls e.x.
http://www.example.com/prod/public/home
My angular app is hosted in the prod/public
directory.
in my public/index.html
:
<base href="/prod/public/" />
my routes are like :
$stateProvider
.state('home', {
url: '/home',
templateUrl: function($stateParams) {
var path = 'app/users/views/home.html';
return path;
},
controller: 'HomeCtrl'
})
Directory structure :
public_html
-.htaccess
- other folders
- prod
- public
- app
- index.html
- bower.json
- .htaccess
- package.json
- gulpfile.js
- Readme.md
.htaccess
inside prod
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 : http://www.example.com/prod/public/home
Requirement :
url should be http://www.example.com/home
instead of http://www.example.com/prod/public/home
base href
is supposed to do. If you don't want it to do that, don't use it...? – Osborne