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.

    评论

报告相同问题?

悬赏问题

  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用