Home  >  Article  >  Backend Development  >  在GAE上搭建PHP环境并开启URL重写_PHP教程

在GAE上搭建PHP环境并开启URL重写_PHP教程

WBOY
WBOYOriginal
2016-07-20 10:58:36966browse

1.下载quercus:

http://quercus.caucho.com/

版本当然最新的最好,因为原则上来说新版本对php支援程度更高,但是在自己测试的时候发现最新的4.0.25存在一点问题,于是换用4.0.18版本.

选择WAR格式的文件下载,利用Winrar解压,将WEB-INFlib的jar拷贝至GAE工程下的warWEB-INFlib目录

2.配置Quercus:

在appengine-web.xml中配置对php文件的支持:

  1. static-files> 
  2.     exclude path="/**.php" /> 
  3. static-files> 
  4. resource-files> 
  5.     include path="/**.php" /> 
  6. resource-files> 

在web.xml中添加一个servlet:

  1. servlet> 
  2.     servlet-name>Quercus Servletservlet-name> 
  3.     servlet-class>com.caucho.quercus.servlet.GoogleQuercusServletservlet-class> 
  4. servlet> 

添加对php文件的映射:

  1. servlet-mapping> 
  2.     servlet-name>Quercus Servletservlet-name> 
  3.     url-pattern>*.phpurl-pattern> 
  4. servlet-mapping> 

3.实现URL重写(通过UrlRewriteFilter实现):

下载UrlRewriteFilter,将urlrewritefilter-*.jar拷贝在工程的warWEB-INFlib目录下

在web.xml中添加URL过滤

  1.  filter> 
  2.     filter-name>UrlRewriteFilterfilter-name> 
  3.     filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilterfilter-class> 
  4. filter> 
  5. filter-mapping> 
  6.     filter-name>UrlRewriteFilterfilter-name> 
  7.     url-pattern>/*url-pattern> 
  8.     dispatcher>REQUESTdispatcher> 
  9.     dispatcher>FORWARDdispatcher> 
  10. filter-mapping> 

在工程的warWEB-INF目录下新建一个Url重写配置文件:urlrewrite.xml

  1. xml version="1.0" encoding="utf-8"?> 
  2. nbsp;urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" 
  3.         "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd"> 
  4.   
  5. urlrewrite> 
  6.     rule enabled="true" match-type="regex"> 
  7.       note>UrlRewritenote> 
  8.       condition type="request-filename" operator="notfile" name="notfile" next="and"/> 
  9.       condition type="request-filename" operator="notdir" name="notdir" next="and"/> 
  10.       from>/(.*)from> 
  11.       to last="true" type="forward">/index.phpto> 
  12.     rule> 
  13. urlrewrite> 
  14.   

这条规则就等同于.htaccess中的:

RewriteCond %{SCRIPT_FILENAME} !-f

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1

注意:这条规则可能会导致GAE本地管理http://localhost:8888/_ah/admin/失效,由于时间关系就不再修正.

4.测试:

在工程的war目录下新建一个index.php文件:

  1. php 
  2. echo 'pre>'; 
  3. print_r($_SERVER); 
  4. ?> 

由于我已经将index.php设置为welcome文件,所以直接打开http://localhost:8888/

效果如图所示:

\

附上一些参考资料:

http://blog.caucho.com/2009/04/28/quercus-on-the-google-app-engine/

http://blog.caucho.com/2009/05/31/quercus-on-google-app-engine/

http://tuckey.org/urlrewrite/#documentation

PHPer们还在犹豫什么,赶紧上吧~


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445669.htmlTechArticle1.下载quercus: http://quercus.caucho.com/ 版本当然最新的最好,因为原则上来说新版本对php支援程度更高,但是在自己测试的时候发现最新的4.0.25存在...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn