Google App Engine重定向/重写

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

 #重定向所有域的所有请求 “www.domain.com”
RewriteCond%{HTTP_HOST}!^ www \ .domain \ .com [NC]
RewriteRule ^(。*)http://www.domain.com/$1 [L,R = 301, NC]

#n将所有移动版本请求重定向到移动子域
RewriteCond%{REQUEST_URI} ^ /([az] [az])/ mobile(/)?(。*)
RewriteRule ^([az ] [az])/ mobile(/)?(。*)https://m.domain.com/$1/$3 [R = 301,L]

#如果网址包含“.php”,则 该请求应由该特定脚本处理
RewriteCond%{THE_REQUEST}(。* \ .php)[NC]
RewriteRule ^([az] [az])/(。*)/ $ 2 [L]

#大多数其他请求应由redirector.php
RewriteCond%{THE_REQUEST}处理!(/([az] [az])/ controls /.*)
RewriteCond%{THE_REQUEST}!(/ api /.*)

RewriteCond%{THE_REQUEST}!(/ admin /.*)
RewriteCond%{HTTP_HOST}!^ m \ .domain \ .com [NC]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FIL ENAME}!-d
RewriteRule ^ redirector.php [L]
</ code> </ pre>

我遇到的问题有三种:</ p>


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

    我已经检查了 https://cloud.google.com/appengine/docs/php/config/appconfig https://cloud.google.com/appengine/docs/python/config/appconfig </ p>
    </ div>

展开原文

原文

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

php

1个回答



有一个 mod_rewrite 演示。 </ p>

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

展开原文

原文

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.

dongluyi5123
dongluyi5123 是的,我确实已经阅读并检查出来了,但是所有人真正做的就是在上面的示例中将所有内容重定向到redirector.php,然后在php中使用复杂的preg替换和文件检查放置一个巨大的case / switch条件,而不是 使用原始请求而不是完全按下脚本。
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐