I already have done $locationProvider.html5Mode(true);
but it is not working. Whenever I access http://example.com
it goes to http://example.
If you want to remove this prefix, add this code to your config:
appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
Source here for more information.
If you want to remove the whole prefix (#
and not only !
), you may try this solution:
1) Activate the HTML5 mode and remove the prefix !
in your module config
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('');
2) And then set base to /
in the <head>
on your index.html
<head>
...
<base href="/">
</head>
Add to your html file <head> <base href="/foldername/"> </head>
and this one is for your app.js $locationProvider.html5Mode(true);
this is for .htaccess
create file if you don't have.
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /foldername/
Below code will remove exclamatory (!) mark in URL
$locationProvider.hashPrefix('');
or else go to Routing issue with AngularJS project using yeoman setup
it worked for me
Add the following to app.js
app.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
If you are in .NET stack with MVC with AngularJS, this is what you have to do to remove the '#' from url:
1.Set up your base href in your _Layout page:
<head> <base href="/"> </head>
2.Then, add following in your angular app config :
$locationProvider.html5Mode(true)
$locationProvider.hashPrefix("!");
$locationProvider.hashPrefix('');
Please check this question: AngularJS ui-router application has /#!/ in the URL