使用Google Appengine和Java删除.html扩展名 [英] Remove .html extension using Google Appengine with Java

查看:109
本文介绍了使用Google Appengine和Java删除.html扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里令人难以置信的困惑。我一直在使用Google Appengine作为我们的网络服务器,到目前为止它一直在努力工作,但是我有一个请求,让网页加载时没有.html扩展名。我一直在做一些阅读,看到我需要创建一个 app.yaml 文件来将url映射到其他东西?这是我到目前为止的文件:

  application:company-website 
version:1
运行时:java
线程安全:true

处理程序:
- url:/ about
脚本:about.html

我一直在尝试阅读如何在他们的文档站点上执行此操作,但似乎无法找到任何引用如何删除扩展名的内容让它指向正确的html文件。谁能帮我吗?我可以在 appengine-web.xml 文件中执行此操作吗?看起来我可以在那里创建一个 app.yaml 文件。



任何帮助都可以赞赏。感谢!



编辑:尝试了一些更多的事情。试图移动文件我试图删除扩展到自己的文件夹所以:

  / root 
-index.html
- / about
--index。 html

当我输入我的 domain.com/about / 它似乎正在工作,但是当我键入 domain.com/about 时,它不会。非常令人沮丧。

解决方案

在理想的世界中,我们可以选择在基础Web服务器中配置像apache的mod_rewrite这样的重写。可悲的是,在这样的级别上配置重写是不可能的。



我搜索了一下,发现重写最常见的答案是用户 UrlRewriteFilter 自己连接servlet 。这两个选项在



两者都以相同的方式工作,并要求应用程序通过应用程序引擎提供静态内容。由于您的所有静态文件都是从Google的内容交付网络(cdn)迁移到您的瓶颈应用,因此这会导致应用引擎实例小时数和响应速度变慢。这些aproaches可能还需要您将静态文件部署为资源( How - 要配置静态文件和资源),至少这是我之前做过的。



这些是您拥有的纯Java选项。 app.yaml 描述的 Josep Valls 将与App Engine上的Java协同工作。这里的主要问题是如果app.yaml配置低到足以成为谷歌在其cdn中识别的重写,或者由于所有内容都通过实例提供服务,您是否仍会耗尽实例小时。



文档告诉我们:


为了提高效率,App Engine从应用程序文件中分别存储并提供
的静态文件。静态文件在
应用程序的文件系统中不可用。如果数据文件需要通过应用程序代码读取
,那么数据文件必须是应用程序文件,并且
不得与静态文件模式匹配。


因为这是在解释如何配置静态文件模式处理程序的部分之前出现的,所以应该假设这些处理程序的配置不会打破上面提到的逻辑 - 也就是


存储和提供与应用程序文件分开的静态文件


这个假设是否正确是一个简单的实验,我将按照给定的时间进行操作,并在此处汇报我的发现。

这些都是我可以找到和了解的所有现有选项。如果有人知道这个主题更多,请评论/回复。

c $ c> appengine:devserver 完全忽略了app.yaml中的设置。我将不得不在下一个部署阶段进行试验或使用 mvn gcloud:run



...当天晚些时候:



通过Servlet重写网址(如 Paul Tuckey的UrlRewriteFilter )不适用于静态文件。您将不得不将这些文件部署为资源文件。静态文件位于其他地方,如果被servlet转发,则不会被发现。至少这就是我的理解。


I am incredibly confused here. I've been using Google Appengine for our webserver and it's been working out great so far, but I had a request to have the webpages load without the .html extension. I've been doing some reading and see that I need to create an app.yaml file to map the url to something else? This is what I have in my file so far:

application: company-website
version: 1
runtime: java
threadsafe: true

handlers:
  - url: /about
  script: about.html

I've been trying to read how to do this on their documentation site but I can't seem to find anything referencing how to remove the extension and still have it point to the right html file. Can anyone help me out? Can I just do this in the appengine-web.xml file, also? It seems like I could just do it in there without creating an app.yaml file.

Any help would be appreciated. Thanks!

edit: tried some more things.. Tried moving the file I'm trying to remove the extension on to its own folder like so:

/root
  -index.html
  -/about
     -index.html

And this was OK, when I typed my domain.com/about/ it appears to be working but when I typed domain.com/about it does not. Very frustrating.

解决方案

In an ideal world we would have the option to configure a rewrite like apache's mod_rewrite in the underlying web server. Sadly it is not possible to configure a rewrite on such a level.

I searched around a bit and found that the most common answer for a rewrite is to user either UrlRewriteFilter or to wire up the servlets yourself. Both options are explained in

Both work in the same way and will require the app to serve static content through app engine. This will result in app engine instance hours and slower responses since all you static files move from Google's content delivery network (cdn) to your bottleneck app. The aproaches possibly also require you to deploy your static files as resource instead (How-To configure static-files and resources), at least that is how i have done this before.

These are the 'pure Java' options you have. The app.yaml approach that Josep Valls described will work in with Java on App Engine. The main question here is if the app.yaml configuration is low level enough to be a rewrite that google recognizes in its cdn, or whether you'll still burn through instance hours because all content is served through instances.

The documentation tells us:

For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.

Since this comes right before the section that explains how to configure the static file pattern handlers one should assume that the configuration of such handlers will not break the logic that is mentioned above - that is

stores and serves static files separately from application files

Whether this assumption is correct is an easy experiment which i shall conduct given time and report my findings here.

These are all the existing options I could find and know of. If anyone knows more on this topic, please comment / respond.

EDIT (7.12.2015) My maven target appengine:devserver is completely oblivious to settings in the app.yaml. I'll have to experiment with this during one of the next deployment phases or use mvn gcloud:run.

... later that day:

Rewriting the URL via Servlet (like with Paul Tuckey's UrlRewriteFilter) does not work for static files. You would have to deploy the files as resource files. Static files reside somewhere else and will not be found if forwarded to by a servlet. At least that's how i understand it.

这篇关于使用Google Appengine和Java删除.html扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆