mod_rewrite -> app.yaml

62 views
Skip to first unread message

JeongWon Seo

unread,
Nov 19, 2015, 5:02:07 PM11/19/15
to Google App Engine
I am having trouble with converting the following .htaccess file to app.yaml

<IfModule mod_rewrite.c>
        RewriteEngine On

        RewriteRule ^$ /index.html [L]

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [QSA,L]
</IfModule>

what I did is as below (not working) and I have both index.html and index.php

app.yaml:

- url: /
 
script: index.html

- url: /.*
 
script: mod_rewrite.php


mod_rewrite.php:

$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (dirname($path) == '/' && pathinfo($path, PATHINFO_EXTENSION) == 'php') {
$file = pathinfo($path, PATHINFO_BASENAME);
}
else {
$file = 'index.php';

}

$_SERVER['SCRIPT_NAME'] = '/' . $file;
require $file;




Adam

unread,
Nov 21, 2015, 4:24:01 PM11/21/15
to Google App Engine
The 'script' element won't work for static files like HTML files. You should use the 'static_files' element, for example:

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

A good idea is to put static files in their own directory, for example:

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

Some references:
Reply all
Reply to author
Forward
0 new messages