How to redirect all url to root's index.html?

1,663 views
Skip to first unread message

Koki

unread,
Jul 5, 2018, 9:01:53 AM7/5/18
to Google App Engine

I have deploy my website through the tutorials using Google App Engine.

My website is work now. 

However, it's only works on https://koki-6hats.appspot.com/index.html


For other cases like:

https://koki-6hats.appspot.com/index

https://koki-6hats.appspot.com/

https://koki-6hats.appspot.com/shouldGoToIndex.html

is not worked. 


How can I config the routing rule to make sure all links above can redirect to index.html automatically?


My app.yaml: 

env: flex

runtime: php

runtime_config:

  document_root: .


I found that there are some method using standard environment to do the static redirection. But when I tried to use that approach, my index.html breaks and remain black text and white background only.

Parth Mishra

unread,
Jul 5, 2018, 11:10:19 AM7/5/18
to Google App Engine
What handlers have you specified? 

Dangelo Trindade Santana

unread,
Jul 5, 2018, 11:34:23 AM7/5/18
to google-a...@googlegroups.com
As per [1] the app.yaml should be like this:
runtime: python27
api_version
: 1
threadsafe
: true

handlers
:
- url: /
  static_files: www/
index.html
  upload
: www/index.html

- url: /(.*)
  static_files: www/
\1
  upload
: www/(.*)
Moreover, it is important to keep the folder hierarchy as recommended in the documentation, all folders below the 'www' folder.

[1] https://cloud.google.com/appengine/docs/standard/python/getting-started/hosting-a-static-website

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/f4928cd5-0b92-4bf8-ae7b-1508200b34cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Koki

unread,
Jul 5, 2018, 11:41:01 AM7/5/18
to Google App Engine
On my latest deployment I’m using flex environment. So didn’t write any handler due to those are not worked (maybe I’m wrong, please point out). I’m just using the simple app.yaml that I wrote in my question...

Koki

unread,
Jul 5, 2018, 12:49:09 PM7/5/18
to Google App Engine
And one more question,
if I use your suggested app.yaml,
and for example the folder structure is:

root
- www
  - index.html
  - folderA
    - index.html
  - folderB
    - index.html

How do I modify the app.yaml to:

1. Show folderA's index.html when the url is http://domain/folderA/(anything behind)
2. Show folderB's index.html when the url is http://domain/folderB/(anything behind)
3. Show www's index.html when not match case 1 and 2

Thank you for your answering. And sorry for if I ask some low level questions... because I have no any idea to web stuffs...

Dan S (Cloud Platform Support)於 2018年7月5日星期四 UTC+8下午11時34分23秒寫道:

Koki

unread,
Jul 5, 2018, 12:49:09 PM7/5/18
to Google App Engine
Dan! Thank you for your reply!
After your suggestion, I changed my app.yaml to this:
runtime: python27
api_version: 1
threadsafe: true

default_expiration: "3m"

handlers:
- url: /(.*\.(appcache|manifest))
  mime_type: text/cache-manifest
  static_files: static/\1
  upload: static/(.*\.(appcache|manifest))

- url: /(.*\.atom)
  mime_type: application/atom+xml
  static_files: static/\1
  upload: static/(.*\.atom)

- url: /(.*\.crx)
  mime_type: application/x-chrome-extension
  static_files: static/\1
  upload: static/(.*\.crx)

- url: /(.*\.css)
  mime_type: text/css
  static_files: static/\1
  upload: static/(.*\.css)

- url: /(.*\.eot)
  mime_type: application/vnd.ms-fontobject
  static_files: static/\1
  upload: static/(.*\.eot)

- url: /(.*\.htc)
  mime_type: text/x-component
  static_files: static/\1
  upload: static/(.*\.htc)

- url: /(.*\.html)
  mime_type: text/html
  static_files: static/\1
  upload: static/(.*\.html)

- url: /(.*\.ico)
  mime_type: image/x-icon
  static_files: static/\1
  upload: static/(.*\.ico)

- url: /(.*\.js)
  mime_type: text/javascript
  static_files: static/\1
  upload: static/(.*\.js)

- url: /(.*\.json)
  mime_type: application/json
  static_files: static/\1
  upload: static/(.*\.json)

- url: /(.*\.m4v)
  mime_type: video/m4v
  static_files: static/\1
  upload: static/(.*\.m4v)

- url: /(.*\.mp4)
  mime_type: video/mp4
  static_files: static/\1
  upload: static/(.*\.mp4)

- url: /(.*\.(ogg|oga))
  mime_type: audio/ogg
  static_files: static/\1
  upload: static/(.*\.(ogg|oga))

- url: /(.*\.ogv)
  mime_type: video/ogg
  static_files: static/\1
  upload: static/(.*\.ogv)

- url: /(.*\.otf)
  mime_type: font/opentype
  static_files: static/\1
  upload: static/(.*\.otf)

- url: /(.*\.rss)
  mime_type: application/rss+xml
  static_files: static/\1
  upload: static/(.*\.rss)

- url: /(.*\.safariextz)
  mime_type: application/octet-stream
  static_files: static/\1
  upload: static/(.*\.safariextz)

- url: /(.*\.(svg|svgz))
  mime_type: images/svg+xml
  static_files: static/\1
  upload: static/(.*\.(svg|svgz))

- url: /(.*\.swf)
  mime_type: application/x-shockwave-flash
  static_files: static/\1
  upload: static/(.*\.swf)

- url: /(.*\.ttf)
  mime_type: font/truetype
  static_files: static/\1
  upload: static/(.*\.ttf)

- url: /(.*\.txt)
  mime_type: text/plain
  static_files: static/\1
  upload: static/(.*\.txt)

- url: /(.*\.unity3d)
  mime_type: application/vnd.unity
  static_files: static/\1
  upload: static/(.*\.unity3d)

- url: /(.*\.webm)
  mime_type: video/webm
  static_files: static/\1
  upload: static/(.*\.webm)

- url: /(.*\.webp)
  mime_type: image/webp
  static_files: static/\1
  upload: static/(.*\.webp)

- url: /(.*\.woff)
  mime_type: application/x-font-woff
  static_files: static/\1
  upload: static/(.*\.woff)

- url: /(.*\.xml)
  mime_type: application/xml
  static_files: static/\1
  upload: static/(.*\.xml)

- url: /(.*\.xpi)
  mime_type: application/x-xpinstall
  static_files: static/\1
  upload: static/(.*\.xpi)

# image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
  static_files: static/\1
  upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))

# audio files
- url: /(.*\.(mid|midi|mp3|wav))
  static_files: static/\1
  upload: static/(.*\.(mid|midi|mp3|wav))  

# windows files
- url: /(.*\.(doc|exe|ppt|rtf|xls))
  static_files: static/\1
  upload: static/(.*\.(doc|exe|ppt|rtf|xls))

# compressed files
- url: /(.*\.(bz2|gz|rar|tar|tgz|zip))
  static_files: static/\1
  upload: static/(.*\.(bz2|gz|rar|tar|tgz|zip))

# index files
- url: /(.*)
  static_files: static/index.html
  upload: static/index.html

# site root
- url: /
  static_files: static/index.html
  upload: static/index.html

It works perfectly for


But, when the url is https://koki-6hats.appspot.com/anything/[withonemorelevel], 
it seems still can link to index.html, but all css, js, etc are broken.

Do you have any idea to fix?


Dan S (Cloud Platform Support)於 2018年7月5日星期四 UTC+8下午11時34分23秒寫道:
As per [1] the app.yaml should be like this:

Yasser Karout (Cloud Platform Support)

unread,
Jul 6, 2018, 12:59:29 PM7/6/18
to Google App Engine
The following handlers will navigate to pages according to your requirements

- url: /
  static_files: www/
index.html
  upload
: www/index.html


- url: /folderA/(.*)
  static_files
: folderA/index.html
  upload
: folderA/index.html
 
- url: /folderB/(.*)
  static_files
: folderB/index.html
  upload
: folderB/index.html
 
- url: /folderA
  static_files: folderA/
index.html
  upload
: folderA/index.html
 
- url: /folderB
  static_files: folderB/
index.html
  upload
: folderB/index.html
 
- url: /(.*)
  static_files: www/
index.html
  upload
: www/index.html


This configuration will navigate to www if nothing is typed, and to folderA or folderB irrelevant of what is after the slash by using (.*), which means any string of characters is accepted. 

I also added folderA and folderB with no slashes in case the user did not specify any pages. And lastly /(.*) to catch all other urls that do not match the previous handlers.
Reply all
Reply to author
Forward
0 new messages