0

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 Answer 1

1

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.

1
  • Yes I did read and check that out, but all that one is really doing is to redirect everything to redirector.php in my above example, and then putting a huge case/switch condition with complex preg replaces and file checks in php, rather than using the original request and not hitting the scripts at all.
    – Lincoln
    Nov 24, 2014 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.