How do I convert this .htaccess
file to an app.yaml
file?
Here is the .htaccess
file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!.*?public).* index.php [QSA,L]
I need to do this to run an app using PHP on Google App Engine.
The reason I'm asking this question, is because Google specifically recommends a code example in their official documentation that is stored in Git Hub called Dr Edit. The Dr Edit code example has a .htaccess
file, but no app.yaml
file. And, in the READ ME
file, the very first step for setting up the application, is to create a Google App Engine application. So I guess Google has provided a code example that insinuates it will run on Google App Engine, but it won't.
Supposedly Google is monitoring Stack Overflow for issues related to GAE, so I hope they read this.
As the name
.htaccess
implies, it can control access to a directory. The.htaccess
files are read on every request. I guess that means that every HTTP request to the domain name must go through the.htaccess
file. So it seems like the.htaccess
file is like agatekeeper
. From Wikipedia, it seems that the.htaccess
file can be used to block certain IP address from loading a web page.The first line of the
.htaccess
file is:RewriteEngine On
That line of code:
RewriteEngine
is an Apache Directive which turns the ApacheRewriting Engine
on or off.So that
.htaccess
file is looking at every request, taking the request, then pushing out a different request.It seems that the
app.yaml
file can not directly take one URL request, and push out a different request, BUT theapp.yaml
file can take a URL request, and then run a PHP script, that will change the request.So, in the
app.yaml
file, the section that takes the URL, then redirects to a script, would look like this:Catch the incoming URL requests and cause the
mod_rewrite.php
file to run.Redirect URL requests with app.yaml
The second line of the
.htaccess
file is:RewriteCond %{REQUEST_FILENAME} !-f
This is a test, looking for a match in the incoming URL request. The
-f
at the end is for:Oh wait! There is an exclamation point in front of it. That's probably a test for logical not. So, if it's NOT a regular file?
Whatever that means. What is the difference between a regular file and everything else? What's an irregular file? lol idk. Anyway, it's looking for a file I guess.
From the Apache documentation, here is a quote:
So that
%{REQUEST_FILENAME}
part of the second line is what Apache is calling aServer-Variable
, and the specificServer-Variable
isREQUEST_FILENAME
.Here is a quote from the Apache documentation:
So I guess the
.htaccess
file is looking for something that looks like a path to files on your local computer?Finally there is the
Rewrite Rule
Apache RewriteRuleWhat is the
QSA
at the end for? I guess it's called a flag, and:QSA seems to stand for
Query String Append
. If the incoming URL has a query string on the end of it, how do you want it dealt with?The [L] prevents any further rewriting rules to be appended
Appache L rewrite flag Appache Documentation QSA
The character (^) is called a caret. I don't know why it's used at the beginning. The syntax for the Appache Rewrite directive is:
RewriteRule pattern target [Flag1,Flag2,Flag3]
So the caret is part of the pattern being detected. That target is simply
index.php
. So it looks like if lots of different possible requests simply get routed back to theindex.php
file, which is the very first thing the application runs.The asterisk at the end is probably a wildcard for any extension.
I think you're out of luck :-( Rewrite is an Apache module but AppEngine is based on Jetty, so you must redesign for that. You might be able to use one of the Bundled Servlets, Filters, and Handlers but none of them are a direct substitute for Apache Module mod_rewrite. Some people have used Apache as a front end before Jetty, but that is a clumsy approach. Sorry.
Here is information about how to simulate Apache mod_rewrite $_GET['q'] routing for a PHP App Engine app, in case that's helpful.