dongzuan4917 2014-11-21 15:51
浏览 59

Google App Engine重定向/重写

I'm migrating my PHP (LAMP) application to a Google App Engine hosting. I've done most of the stuff but now I'm stuck on converting the .htaccess rules to the app.yaml version.

# Redirect all requests for any domain not being "www.domain.com"
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301,NC]

# Redirect all requests for the mobile version to the mobile subdomain
RewriteCond %{REQUEST_URI} ^/([a-z][a-z])/mobile(/)?(.*)
RewriteRule ^([a-z][a-z])/mobile(/)?(.*) https://m.domain.com/$1/$3 [R=301,L]

# If the URL contains ".php", then the request should be handled by that particular script
RewriteCond %{THE_REQUEST} (.*\.php) [NC]
RewriteRule ^([a-z][a-z])/(.*) /$2 [L]

# Most of the other requests should be handled by redirector.php
RewriteCond %{THE_REQUEST} !(/([a-z][a-z])/controls/.*)
RewriteCond %{THE_REQUEST} !(/api/.*)
RewriteCond %{THE_REQUEST} !(/admin/.*)
RewriteCond %{HTTP_HOST} !^m\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ redirector.php [L]

The problems I have are of three kinds:

  1. How to redirect the user to www.domain.com if visiting through domain.com
  2. How do I rewrite a 2 character language code that comes exactly after the domain name, and pass it as a GET parameter to PHP (added with the other parameters)
  3. How do I check if the requested file / directory exists, so if not, load a redirector.php file that will handle pretty/virtual links itself.

I've checked the documentation at https://cloud.google.com/appengine/docs/php/config/appconfig and https://cloud.google.com/appengine/docs/python/config/appconfig

  • 写回答

1条回答 默认 最新

  • dongyu2300 2014-11-23 21:27
    关注

    There is a mod_rewrite demo included in the SDK.

    It should show you how to do all of the above, and has an app.yaml file that shows you how to configure it to call the script.

    评论

报告相同问题?