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.

    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题