谷歌应用引擎重定向/重写



我正在将我的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]

我遇到的问题有三种:

  1. 如果通过 domain.com 访问,如何将用户重定向到 www.domain.com
  2. 如何重写正好在域名之后的 2 个字符的语言代码,并将其作为 GET 参数传递给 PHP(与其他参数一起添加)
  3. 如何检查请求的文件/目录是否存在,因此,如果不存在,请加载一个重定向器.php文件,该文件将自行处理漂亮/虚拟链接。

我已经检查了 https://cloud.google.com/appengine/docs/php/config/appconfig 和 https://cloud.google.com/appengine/docs/python/config/appconfig 的文档

SDK 中包含mod_rewrite演示。

它应该向您展示如何执行上述所有操作,并有一个 app.yaml 文件,向您展示如何配置它以调用脚本。

最新更新