简体   繁体   English

如何使用Google App Engine进行网址重写-HTML5模式不起作用

[英]How to url rewrite with Google app engine — HTML5 mode not working

I am using Angularjs, Java for my application. 我正在为我的应用程序使用Java Angularjs。 Initially I am using tomcat to run my application. 最初,我使用tomcat运行我的应用程序。 when I run my project it will open the URL 当我运行项目时,它将打开URL

http://localhost:8080/projectname HTTP://本地主机:8080 /项目名称

so I configured my base tag and html5 mode as 所以我将基本标记和html5模式配置为

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

with welcome file configured to main.html in web.xml and I added the code 在web.xml中将欢迎文件配置为main.html,我添加了代码

<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). 使ui-router在html5模式下工作(在ui-router问题页面中提到)。

Then I change my project to google app engine standard java project and when I run my project it open with url 然后我将项目更改为Google App Engine标准Java项目,并在运行项目时使用url打开

http://localhost:8080 HTTP://本地主机:8080

so I changed my base tag to 所以我将基本标签更改为

<base href="/">

with this there no problem in main.html but my routing are not working. 与此相关,在main.html中没有问题,但是我的路由不起作用。 When I use $state.go its working. 当我使用$ state.go它的工作。 But on refreshing or manually entering the url i'm getting 404 error. 但是在刷新或手动输入网址时,出现404错误。 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 我已经在web.xml文件中配置了spring

<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? 看来它正在将所有url请求映射到spring,有什么办法解决吗?

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 问题在于刷新页面,如果您打开基础并单击将起作用的任何链接,则需要编写代码以重写URL

For IIS running application we need to add: 对于运行IIS的应用程序,我们需要添加:

<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 查看IIS配置的详细信息

Sorry, I never worked with tomcat 对不起,我从来没有和tomcat一起工作过

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM