App route doesn't work on Python3 http.server when accessed by omnibox
PuruVijay14 opened this issue · comments
I have this URL using app route localhost/login
which shows the element pe-login
. But when I access it using the omnibox in chrome and the server is Python 3 http.server, I see a 404 page.(of server)
How do I correct this?
Thank you
PS: I use polymer-2-starter-kit
When using app-route
for it to catch requests to sub-addresses you need to redirect requests to the main entrypoint page.
This can be done with python, but would require manually extending SimpleHTTPServer
.
An easier way to serve this locally is to use the polymer-cli
and use polymer serve
which will automatically redirect requests to your entrypoint page.
You can find more information about the polymer-cli
here:
https://github.com/Polymer/polymer-cli
Thanks Jason. But I will be deploying the site on a site ground. Perhaps they also use http.server. What am I to do in that case?
You can use a .htaccess
file with something like this:
### Redirect all non-existant pages to index.html
<IfModule mod_rewrite.c>
RewriteEngine on
# Don't redirect specific file types
RewriteCond %{REQUEST_URI} \.(jpe?g|png|gif|css|js|ico|map|txt)$ [NC,OR]
# Don't redirect my-<view>.html pattern for proper 404 pages
RewriteCond %{REQUEST_URI} my-.+\.html$ [NC,OR]
# Don't redirect any files which exist
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
# If matches any exceptions, don't redirect
RewriteRule ^.*$ - [NC,L]
# If doesn't match any exceptions, redirect to `/index.html`
RewriteRule ^(.*) /index.html [NC,L]
</IfModule>
Edit: This is assuming you're referring to Siteground or similar service which uses Apache based hosting.
@jsilvermist has it right on the money. This is the method we use on our node / firebase environments as well.