title: URL Rewrite - Google App Engine (Python)
body: <p>I followed a tutorial to create pretty URLs for my site that I plan to host on Google App Engine (Python). </p>
  
  <p>The problem is it won't display the index pages inside subdictories.</p>
  
  <p>I have a file called abc.html which loads fine at this address
  http://<b></b>www.testsite.com/abc</p>
  
  <p>But I have index files in subdirectories (xyz and 123) which won't load into the content area (blank spacing in content area)</p>
  
  <p>Subdirectory xyz with index.html:
  <a href="http://www.testsite.com/xyz" rel="nofollow">http://www.testsite.com/xyz</a></p>
  
  <p>Subdirectory 123 with index.html  inside directory xyz:
  <a href="http://www.testsite.com/xyz/123" rel="nofollow">http://www.testsite.com/xyz/123</a></p>
  
  <p>Here is the code I used</p>
  
  <p><strong>app.yaml</strong></p>
  
  <pre><code>application: testsite
  version: 1
  runtime: python
  api_version: 1
  threadsafe: yes
  
  default_expiration: "1d"
  
  handlers:
  - url: /(.*\.(gif|png|jpg|ico|js|css|swf|xml))
    static_files: \1
    upload: (.*\.(gif|png|jpg|ico|js|css|swf|xml))
  
  - url: /.*
    script: main.py
  </code></pre>
  
  <p><strong>main.py</strong></p>
  
  <pre><code>import os
      from google.appengine.ext import webapp
  from google.appengine.ext.webapp.util import run_wsgi_app
  from google.appengine.ext.webapp import template
  
  class MainPage(webapp.RequestHandler):
     def get(self, p):
        if p:
           page = p + ".html"
        else:
           p = "main"
           page = p + ".html"
  
            if not os.path.exists(page):
           page = "404.html"
  
        template_values = {
              "page" : page,
                  p: "first", 
        };
  
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
  
  application = webapp.WSGIApplication([(r'/(.*)', MainPage)],debug=True)
  
  def main():
     run_wsgi_app(application)
  
  if __name__ == "__main__":
     main()
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
     &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
     &lt;title&gt;TestTitle&lt;/title&gt;
     &lt;link href="/static/style.css" rel="stylesheet" type="text/css" media="screen" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
     &lt;div id="header"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="main"&gt;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="abc"&gt;abc&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="xyz/123"&gt;xyz&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
     &lt;/div&gt;
  
     &lt;div id="content"&gt;
        &lt;!-- this is where content will be loaded --&gt;
  
        {% if page %}
           {% include page %}
        {% else %}
           {% include "main.html" %}
        {% endif %}
  
     &lt;/div&gt;
  
     &lt;div id="sidebar"&gt;
        TestSideBar
     &lt;/div&gt;
  
     &lt;div id="footer"&gt;
        TestFooter
     &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PS: The tutorial I followed was a dynamic page + URL rewrite guide. The dynamic page aspect is not really necessary. I just couldn't find a tutorial that would get pretty URLs working.</p>