【问题标题】:Google App Engine Redirects/RewriteGoogle App Engine 重定向/重写
【发布时间】: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]

我遇到的问题分为三种:

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

我查看了https://cloud.google.com/appengine/docs/php/config/appconfighttps://cloud.google.com/appengine/docs/python/config/appconfig 的文档

【问题讨论】:

    标签: php .htaccess google-app-engine


    【解决方案1】:

    SDK 中包含一个mod_rewrite 演示。

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

    【讨论】:

    • 是的,我确实阅读并检查了这一点,但在我上面的示例中,真正要做的是将所有内容重定向到 redirector.php,然后使用复杂的 preg 替换放置一个巨大的 case/switch 条件并在 php 中进行文件检查,而不是使用原始请求并且根本不点击脚本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 2013-11-14
    • 2011-04-14
    • 2012-09-22
    • 2011-10-09
    • 2016-07-09
    • 2015-11-20
    相关资源
    最近更新 更多