如何删除“公开"从 url 使用 Zend 框架中的路由 [英] How to remove "public" from url using routeing in zend framework

查看:19
本文介绍了如何删除“公开"从 url 使用 Zend 框架中的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Zend 中的一个问题,我在 .htaccess 中编写规则以从 url 中删除public",如下所示,

An one issue in my zend, i write rule in .htaccess to remove "public" from url as following,

------------------------------------------------------------------------ 
RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain-name.com/$ [OR]<br/>
ReWriteCond %{REQUEST_URI} !public/<br/>
ReWriteRule ^(.*)$ public/$1 [L]<br/>
------------------------------------------------------------------------ 

但是在 Zend 中有 ROUTE 方法,我已经将它用于多种语言以在 url LIKE www.domain-name.com/en/ 中设置语言代码,使用 zend_controller_router_route_chain,

but there is ROUTE method in zend, i have use it for multiple language to set language code in url LIKE www.domain-name.com/en/ , using zend_controller_router_route_chain,

在实现这个方法之前,我的网址是www.domain-name.com 但是
当我在我的 zend 项目中使用这种方法时,它可能会覆盖从 URL 中删除public"的 .htaccess 规则,或者使用相同的内容和public"显示在 url 中,例如 www.domain-name.com/public.

before this method implemented, my url is www.domain-name.com but
when i use this method in my zend project, may be it overwrites .htaccess rule of removing "public" from URL or something happen using same and "public" is displaying in url like www.domain-name.com/public.

那么是否有任何方法或技巧可以使用 ZEND 框架中的任何 路由 方法从 URL 中删除 PUBLIC ???

so IS THERE ANY METHOD OR TRICK TO REMOVE PUBLIC FROM URL USING ANY METHOD OF ROUTE IN ZEND FRAMEWORK ???

谢谢,

MRJethva.

推荐答案

以下适用于我使用 ZF2.2

The following works for me using ZF2.2

在ZF2根目录创建index.php并添加如下内容:

Create index.php on ZF2 root directory and add the following content:

<?php 
define('RUNNING_FROM_ROOT', true);
include 'public/index.php';

在 ZF2 根目录下创建 .htaccess 并添加以下内容:

Create .htaccess on ZF2 root directory and add the following content:

SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteRule .* index.php

最后,在 layout.phtml 文件的顶部添加这个条件语句:

Finally, add this conditional statement in the top of your layout.phtml file:

<?php 
if (defined('RUNNING_FROM_ROOT')) {
  $this->plugin('basePath')->setBasePath($this->basePath().'/public');
} ?>

享受吧!

参考:http://akrabat.com/zend-framework/zend-共享主机上的框架/

这篇关于如何删除“公开"从 url 使用 Zend 框架中的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆