Basically my directory layout looks something like this:
- demo
|
+ + exmaple1
| |
| + index.html
| + some-script.js
|
+ + example2
...
What I want to achieve is to make it such that
my.url/demo/example1 shows /demo/example1/index.html
my.url/demo/example1/some-script.js shows /demo/example1/some-script.js
my.url/demo/example1/index.html redirects to my.url/demo/example1
Here is my app.yaml:
handlers:
# some stuff here
- url: /demo/([^/]+)$
static_files: demo/\1/index.html
upload: demo/(.+)/index\.html$
- url: /demo
static_dir: demo
It does return the correct page for my.url/demo/example1, but when I try to request my.url/demo/example1/some-script.js, it returns 404. Why is that and how should I fix it?
You don't have a handler for the .js file. And by "redirect", do you mean a full 301 redirect, or just to show the index.html static file?
Does this do what you need?
- url: /demo/(.*)/(.*)
static_files: demo/\1/\2
upload: demo/(.*)/(.*)
- url: /demo/(.*)
static_files: demo/\1/index.html
upload: demo/(.*)/index.html
Related
I am using Google App Engine (go).. and I am looking to redirect https://www.ibikeride.com/scotland/comrie-croft-mountain-bike-trails/amp
to https://www.ibikeride.com/scotland/comrie-croft-mountain-bike-trails
I looked on google app engine docs on redirects but is more than pretty vague. I assume it is a redirect set up in the app.yaml file under handlers.
I actually want to redirect all files ending in "amp" to the same url structure without the amp
if there is a straightforward way of doing that and to avoid me doing a 100+ individual redirect.
For relevant info here is how my current handlers look NB(before attempting this). I have a few handlers to remove the '.html' from the end of url's (for specific categories) and also one at the end to redirect all files to secure 'https'
Any help appreciated
handlers:
# this serves your static/some/path/<file>.html asset as /some/path/<file>.html
- url: /(england/.*\.html)$
static_files: static/\1
upload: static/england/.*\.html$
# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(england/.*)$
static_files: static/\1.html
upload: static/england/.*\.html$
# this serves your static/some/path/<file>.html asset as /some/path/<file>.html
- url: /(scotland/.*\.html)$
static_files: static/\1
upload: static/scotland/.*\.html$
# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(scotland/.*)$
static_files: static/\1.html
upload: static/scotland/.*\.html$
# this serves your static/some/path/<file>.html asset as /some/path/<file>.html
- url: /(wales/.*\.html)$
static_files: static/\1
upload: static/wales/.*\.html$
# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(wales.*)$
static_files: static/\1.html
upload: static/wales/.*\.html$
# this serves your static/some/path/<file>.html asset as /some/path/<file>.html
- url: /(northern-ireland/.*\.html)$
static_files: static/\1
upload: static/orthern-ireland/.*\.html$
# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(northern-ireland.*)$
static_files: static/\1.html
upload: static/northern-ireland/.*\.html$
#redirect always to https
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
Since you are using the classification part amp at the end instead of the beginning I would suggest you to create a small service that redirects automatically.
For instance in app.yaml:
handlers:
....
- url: /.*/amp
script: main.go
And the code (main.go):
package main
import (
"fmt"
"net/http"
)
type Handler struct{}
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
uri := r.URL.Path
length := len(uri)
newUrl := uri[0:length-3] // Remove trailing amp
http.Redirect(w, r, newUrl, http.StatusMovedPermanently)
return
}
func main() {
handler := new(Handler)
http.ListenAndServe(":8080", handler)
}
I have a simple Flask application.
On local host, Flask redirects to the canonical URL with the trailing slash. So if I visit localhost:8080/test, it will take me to localhost:8080/test/
However, when I deploy to google app engine,
I try ***.appspot.com/test , it just return 404 error.
It does not redirect to the canonical URL with the trailing slash.
I really can not figure out the problem. I use gae-init https://github.com/gae-init/gae-init
Here is my app.yaml file
service: default
instance_class: F1
runtime: python27
api_version: 1
threadsafe: true
builtins:
- appstats: on
- deferred: on
- remote_api: on
inbound_services:
- warmup
libraries:
- name: ssl
version: latest
error_handlers:
- file: templates/error_static.html
handlers:
- url: /favicon.ico
static_files: static/img/favicon.ico
upload: static/img/favicon.ico
- url: /robots.txt
static_files: static/robots.txt
upload: static/robots.txt
- url: /p/(.*\.ttf)
static_files: static/\1
upload: static/(.*\.ttf)
mime_type: font/ttf
expiration: "365d"
- url: /p/(.*\.woff2)
static_files: static/\1
upload: static/(.*\.woff2)
mime_type: font/woff2
expiration: "365d"
- url: /p/
static_dir: static/
expiration: "365d"
- url: /.*
script: main.app
secure: always
redirect_http_response_code: 301
skip_files:
- ^(.*/)?#.*#
- ^(.*/)?.*/RCS/.*
- ^(.*/)?.*\.bak$
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*~
- ^(.*/)?Icon\r
- ^(.*/)?\..*
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^lib/.*
- ^static/dev/.*
- ^static/ext/.*\.coffee
- ^static/ext/.*\.css
- ^static/ext/.*\.js
- ^static/ext/.*\.less
- ^static/ext/.*\.json
- ^static/src/.*
Here is how I handle test
#app.route('/test/')
#auth.login_required
def contact_list():
contact_dbs, contact_cursor = model.Contact.get_dbs(
user_key=auth.current_user_key(),
)
return flask.render_template(
'contact_list.html',
html_class='contact-list',
title='Contact List',
contact_dbs=contact_dbs,
next_url=util.generate_next_url(contact_cursor),
)
The console log is
2018-06-14 02:45:09.388 JST
301 - Moved Permanently: https://ktest321986.appspot.com/contact (/base/data/home/apps/b~ktest321986/20180613t165904.410404733871213095/control/error.py:29)
2018-06-14 02:45:09.389 JST
301 Moved Permanently: None (/base/data/home/apps/b~ktest321986/20180613t165904.410404733871213095/control/error.py:31)
Traceback (most recent call last):
File "lib.zip/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "lib.zip/flask/app.py", line 1791, in dispatch_request
self.raise_routing_exception(req)
File "lib.zip/flask/app.py", line 1774, in raise_routing_exception
raise request.routing_exception
RequestRedirect: 301 Moved Permanently: None
You can try it here :
does not work: https://ktest321986.appspot.com/contact
work: https://ktest321986.appspot.com/contact/
I dont know what is the problem.
However, when I deploy the project from Mac, problem has gone.
If I deploy the project from window 10, problem comes.
So funny!
My App Engine isn't loading php files in sub directory
Directory Structure is from the app.yaml file to the corresponding files.
I'm using Google's App Engine with PHP and my YAML code is below
handlers:
- url: /
script: soap/index.php
- url: /(.+)
script: soap/index.php
- url: /getGEO.php
script: soap/getGEO.php
- url: /tests/XML_GEOOffers.php
script: soap/tests/XML_GEOOffers.php "No handlers matched this URL."
- url: /tests/test.php
script: soap/tests/test.php "No handlers matched this URL."
I also having problem to past the parameters for GET in url
localhost:11080/trace ( my script shows false as no paramter sent )
but when i past the parameters into url, it shows blank page instead for true or false
localhost:11080/trace?Pub=0&Adv=0&SDK=0&HWD=c45f9a729cd349bdf3f21e96d305afde1028be99&OS=0&AV=nothing|nothing&BROWSER=IE&Sub=0&campaign=0&Demo=0
I'd greatly appreciate if anybody can help me with this.
You need to put / last, else it matches every url. Same for your /(.+) handler. Try this order:
handlers:
- url: /getGEO.php
script: soap/getGEO.php
- url: /tests/XML_GEOOffers.php
script: soap/tests/XML_GEOOffers.php #"No handlers matched this URL."
- url: /tests/test.php
script: soap/tests/test.php #"No handlers matched this URL."
- url: /(.+)
script: soap/index.php
- url: /
script: soap/index.php
You don't really need one of the last two, as they point to the same place.
File Structure
ROOT
- app.yaml
- flashfolder/bin-release
-sfx
-maps
-resources
I've tried,
- url: /flashFolder/bin-release/*(.*\.(gif|png|jpg|ico|js|css|swf|xml|tmx|mp3))
static_dir: \1
upload: static/flashFolder/bin-release/(.*\.(gif|png|jpg|ico|js|css|swf|xml|tmx|mp3))
- url: /flashFolder/bin-release/*(.*\.(gif|png|jpg|ico|js|css|swf|xml|tmx|mp3))
static_files: \1
upload: static/flashFolder/bin-release/(.*\.(gif|png|jpg|ico|js|css|swf|xml|tmx|mp3))
- url: /flashFolder/bin-release/
static_dir: \1
Anybody have a link explaining the the URL handlers, other than what Google provides, the python goes right over my head.
I just wanna upload all the folders within bin-release and their contents without having to specifically map them. Is there a wild card I can throw within the bin-release map?
try:
- url: /flashFolder/bin-release/
static_dir: flashFolder/bin-release/
unless you really need to filter based on the file extension
I have all my static files in a folder called html in the root directory. I get the following error while trying to access the index.html in html folder:
-
INFO 2012-07-27 04:07:44,847 dev_appserver.py:2952] "GET /images/logo_footer.jpg HTTP/1.1" 404 -
Here is the folder structure:
Handler code in handlers folder:
class MainHandler(webapp.RequestHandler):
def get (self, q):
if q is None:
q = '../html/index.html'
path = os.path.join (os.path.dirname (__file__), q)
self.response.headers ['Content-Type'] = ContentType.HTML_TEXT
self.response.out.write (template.render (path, {}))
Here is the url rule for images on app.yaml:
- url: /.*
script: notify.app
# image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
static_files: html/images/\1
upload: html/images/(.*\.(bmp|gif|ico|jpeg|jpg|png))
Am I doing anything wrong here?
You need to move the url : /.* section to after the image files section in app.yaml. These are processed in order, and /.* matches everything, so the second - url: line is never used.
Most likely you have another url that matched "/images/logo_footer.jpg" first, and that served an error.
Also, don't know what the \1 in your static_files path is.