【发布时间】:2014-11-21 15:51:03
【问题描述】:
我正在将我的 PHP (LAMP) 应用程序迁移到 Google App Engine 主机。我已经完成了大部分工作,但现在我坚持将 .htaccess 规则转换为 app.yaml 版本。
# 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]
我遇到的问题分为三种:
- 如果通过 domain.com 访问,如何将用户重定向到 www.domain.com
- 如何重写紧跟在域名后面的 2 字符语言代码,并将其作为 GET 参数传递给 PHP(与其他参数一起添加)
- 如何检查请求的文件/目录是否存在,如果不存在,请加载一个将自己处理漂亮/虚拟链接的 redirector.php 文件。
我查看了https://cloud.google.com/appengine/docs/php/config/appconfig 和https://cloud.google.com/appengine/docs/python/config/appconfig 的文档
【问题讨论】:
标签: php .htaccess google-app-engine