1

I uploaded my webpage using google app engine and it is working fine. It is a very simple webpage with 6 static files (.html all of them)

I need to Remove .html extension from URL. For example: I have www.example.com/contact.html, I want www.example.com/contact

My current app.yaml is

runtime: php55
api_version: 1
threadsafe: true

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

- url: /
  static_dir: website

All html files are Inside the "Website" folder, so how can i hide .html extension from URL

So Please help me to fix it.

Rizwan
  • 155
  • 2
  • 10
  • I don't know if this could help you: https://stackoverflow.com/questions/5573485/php-htaccess-pretty-url-in-reverse but anyway, this is a duplicated question: https://stackoverflow.com/questions/48936791/how-to-remove-html-extensions-from-google-cloud-platform-url – Temu Jul 24 '18 at 11:48

2 Answers2

2

If you have just 6 static files and you do not want to use .htaccess, you have to do this:

Instead of

> handlers:
> 
> - url: /   static_dir: website

You could:

handlers:

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

- url: /file1
  static_files: website/file1.html
  upload: website/file1.html

- url: /file2
  static_files: website/file2.html
  upload: website/file2.html

- url: /file3
  static_files: website/what_ever_name.what_ever_format
  upload: website/what_ever_name.what_ever_format
Temu
  • 859
  • 4
  • 11
  • Since it works to you I would appreciate if you accept the answer in order to help the community to quickly locate a answer which works. – Temu Jul 26 '18 at 15:05
0

You could try something like this, but you'll have to not rely on the existing catch-all static_dir handler you have at the end, since that will never be reached due to the new catch-all handler expanding any other file pattern with a .html extension:

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

# handler for specifically requested .html files
- url: /(.*\.html)$
  static_files: website/\1
  upload: website/.*\.html$

# add any other more specific file patterns here, before the catch-all case below

# catch-all handler implicitly serving .html files, no handler below it will be reached
- url: /(.*)$
  static_files: website/\1.html
  upload: website/.*\.html$

# no other handler from this point forward will be reached

Side note: overlapping handler url patterns for static_dir and static_files may cause problems, see Static files are missing

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • when i use above code i get an `ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: The request is invalid. - '@type': type.googleapis.com/google.rpc.BadRequest fieldViolations: - description: 'Value "website/\1" must be a valid regular expression. Details : invalid escape sequence.' field: version.handlers[1].static_files.upload_path_regex - description: 'Value "website/\1.html" must be a valid regular expression. De tails: invalid escape sequence.' field: version.handlers[2].static_files.upload_path_regex` and what about **1** from `static_files: website/\1` – Rizwan Jul 23 '18 at 11:47
  • Apologies, I messed up the `upload` statements. I updated the answer – Dan Cornilescu Jul 24 '18 at 15:44