Rishi0405
Rishi0405

Reputation: 354

How to url rewrite with Google app engine -- HTML5 mode not working

I am using Angularjs, Java for my application. Initially I am using tomcat to run my application. when I run my project it will open the URL

http://localhost:8080/projectname

so I configured my base tag and html5 mode as

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('');
<base href="/projectname/">

with welcome file configured to main.html in web.xml and I added the code

<welcome-file-list>  
    <welcome-file>main.html</welcome-file>  
</welcome-file-list>

<error-page>
    <error-code>404</error-code>
    <location>/</location>
</error-page>

to make ui-router work with html5 mode(mentioned in ui-router issue page).

Then I change my project to google app engine standard java project and when I run my project it open with url

http://localhost:8080

so I changed my base tag to

<base href="/">

with this there no problem in main.html but my routing are not working. When I use $state.go its working. But on refreshing or manually entering the url i'm getting 404 error. My console error is

WARNING: No file found for: /url

I referred many blogs but still confused to configure


I have configured spring in web.xml file

<servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

It seems that it is mapping all the url request to spring, is there any way to solve this?

Upvotes: 0

Views: 292

Answers (1)

Ali Adravi
Ali Adravi

Reputation: 22733

Problem is with refresh the page, if you will open the base and click on any link it will work, you need to write the code for re-write URL

For IIS running application we need to add:

<system.webServer>
    <rewrite>
     <rules> 
      <rule name="Main Rule" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                                 
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/" />
      </rule>
    </rules>
    </rewrite>
</system.webServer>

See detail for IIS configuration

Sorry, I never worked with tomcat

Upvotes: 1

Related Questions