2014-11-21 60 views
0

我将我的PHP(LAMP)应用程序迁移到Google App Engine托管。我已经完成了大部分的工作,但现在我坚持将.htaccess规则转换为app.yaml版本。Google App Engine重定向/重写

# 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. 如何,如果将用户重定向到www.domain.com访问通过domain.com
  2. 如何改写为2个字符的语言代码恰好位于域名后面,并将其作为GET参数传递给PHP(与其他参数一起添加)
  3. 如何检查请求的文件/目录是否存在,如果不存在,请加载redirector.php文件这将处理漂亮/虚拟链接本身。

我在https://cloud.google.com/appengine/docs/php/config/appconfig检查文档和https://cloud.google.com/appengine/docs/python/config/appconfig

回答

1

有SDK中包含的一个mod_rewrite演示。

它应该告诉你如何完成上述所有操作,并且有一个app.yaml文件,告诉你如何配置它来调用脚本。

+0

是的,我确实已经阅读并检查了这一点,但所有这一切实际上是在上面的示例中将所有内容重定向到redirector.php,然后在php中使用复杂的preg替换和文件检查来放置巨大的case/switch条件而不是使用原始请求,而不是使用脚本。 – Lincoln 2014-11-24 08:15:30

相关问题