14

I didn't find a way to remove index.html from the url, because like this looks really ugly.

mydomain.com/index.html#/myview1 
mydomain.com/index.html#/myview2

Is there a way to remove that part, like that url will be so clear where the user is.

mydomain.com/myview1
mydomain.com/myview2

Tnx in advance for your time.

Edit: I just find way that it could work like:

mydomain.com/#/myview1
mydomain.com/#/myview2

which is pretty much better then with index.html.

But still if there is a way for shorter solution let me know.

5
  • 3
    How have you done to remove index.html from url? Commented Oct 29, 2013 at 20:00
  • Read the edit Alavaros. Commented Dec 6, 2013 at 7:39
  • 1
    @Pnct how did you remove index.html as you mentioned in your edit? Commented Jan 3, 2014 at 9:14
  • 1
    @anvarik just remove "index.html" from routing config, and everywhere you use as a link. And as i wrote above as my edit, you should use just the "#" char. But if you are asking about removing completely "index.html" without "#", you should try to activate the html5mode for $location as Eduard Gamonal answered on my question. Commented Jan 3, 2014 at 9:42
  • Is URL-rewriting (mydomain.com/myview1 -> mydomain.com/index.html#/myview1) not an option? It's often cleaner and less work to enforce friendly URLs externally (outside of your framework, say, via mod_rewrite) than to muck around with plumbing, especially in path-y clientside frameworks like Angular/Backbone/etc. Commented May 14, 2014 at 4:30

4 Answers 4

3

Maybe this approach could help:

Add $locationProvider.hashPrefix();, which removes index.html in your URL, in your app.js config. Don't forget to add the new dependency. After that your app.js could look similar to this:

 angular.module('myApp', [
  'ngRoute'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  $locationProvider.hashPrefix(); // Removes index.html in URL

  $routeProvider.otherwise({redirectTo: '/someroute'});
}]);

Note that this does not remove the hashtag. You can find your new route at: .../app/#/someroute

Sign up to request clarification or add additional context in comments.

Comments

2

activate the html5mode for $location

Comments

2

You'll have to do some work on the server side to set this up. html5mode gets you part of the way, but as soon as the user refreshes, the reference to the file will be wrong. You want links that are persistent and can be shared, presumably. Basically make sure any request to url.com/myapp/{etc} (or whatever) gets redirected to index.html and let your angular app sort out the routing.

Comments

0

Use

<rewrite>
    <rules>
        <rule name="RewriteRules" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
      </rule>
  </rules>
</rewrite>

And on Index page

<base href="/" /> 

And on your config use

$locationProvider.html5Mode(true);

It should work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.