【问题标题】:How to remove index.php in url in zend framework如何在zend框架中删除url中的index.php
【发布时间】:2014-03-21 18:20:40
【问题描述】:

我最近安装了一个 zend 框架网站,从一台服务器到另一台服务器。

eg: http://localhost/test/html ----  This is my website url

test 是我的文件夹----所有的zend框架文件都保存在那里...... 但是我的 index.php 文件在 html 文件夹下....而且我也在下面显示 index.php 的代码....

我的网站使用此链接"http://localhost/test/html" 成功运行

test 所在的文件夹

这是我下面的 .htaccess 代码

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

这是我在test文件夹下的index.php文件

set_include_path('.'
        . PATH_SEPARATOR . get_include_path()
        . PATH_SEPARATOR . '../library'

//        . PATH_SEPARATOR . '../application/classes/'
//        . PATH_SEPARATOR . '../application/classes/forms/'
//        . PATH_SEPARATOR . '../application/models/'

          . PATH_SEPARATOR . '../application/default/classes/'
        . PATH_SEPARATOR . '../application/default/classes/forms/'
        . PATH_SEPARATOR . '../application/default/models/'
        . PATH_SEPARATOR . '../application/bo/classes/'
        . PATH_SEPARATOR . '../application/bo/classes/forms/'
        . PATH_SEPARATOR . '../application/bo/models/'
        . PATH_SEPARATOR . '../application/bo/controllers/'
        . PATH_SEPARATOR . '../application/helpers'
);

require_once "../library/Zend/Loader/Autoloader.php";
//session_start();
define("SITE_PATH", "http://localhost/test/");
define("SITE_BO_PATH", "http://localhsot/test/bo/");
define("URL", "/html/");
define("BO_URL", "/html/bo/");
define("BASE_URL", "/html/");
define("LIB_URL", "/library/");
define("IMG_URL", BASE_URL . "public/img/");
define("IMG_BO_URL", BASE_URL . "public/img_bo/");

@Zend_Loader::registerAutoload();

$options = array(
    'layout' => 'layout',
    'layoutContent' => '../application/views/layouts/',
    'contentKey' => 'content');


new DbInitialize();


date_default_timezone_set("Europe/Berlin");

Zend_Layout::startMvc($options);

Zend_Session::setOptions(array('save_path'=>'/vlk_session'));
if(isset($_COOKIE["Zend_Auth_RememberMe"]) && $_COOKIE["Zend_Auth_RememberMe"] !== false){
    Zend_Session::rememberMe("5302000");
    setcookie("Zend_Auth_RememberMe", false, time(), "/");
}



if(!Zend_Session::isStarted()){

    Zend_Session::start();

}



$sessionUUID = new Zend_Session_Namespace("vlk_jsessionId");
$sessionUUID->setExpirationSeconds(6000000);
if(!isset($sessionUUID->UUID)) {
    $sessionUUID->UUID = uniqid('vlk_');
}


$options = array(
    "adapter" => 'csv',
    "content" => 'languages/en.csv',
    "locale" => "en"
);

$translate = new Zend_Translate($options);
$_lingua = "it";

if(isset($_COOKIE["lingua"]) && ($_COOKIE["lingua"] == "it" || $_COOKIE["lingua"] == "en")){
    $_lingua = $_COOKIE["lingua"];
}
$translate->getAdapter()->setLocale($_lingua);
Zend_Registry::set('Zend_Translate', $translate);
$controller = Zend_Controller_Front::getInstance();
$_router = $controller->getRouter();


$_router->addRoute('backoffice',new Zend_Controller_Router_Route_Static('business',array('module' => 'bo','controller' => 'index','action' => 'index')));

$_router->addRoute('fanpage',new Zend_Controller_Router_Route_Static('business/fanpage',array('module' => 'bo','controller' => 'facebook','action' => 'index')));

$_router->addRoute('profile',new Zend_Controller_Router_Route_Static('business/profile',array('module' => 'bo','controller' => 'useredit','action' => 'profile')));

$_router->addRoute('video',new Zend_Controller_Router_Route_Static('business/video',array('module' => 'bo','controller' => 'gestionevideo','action' => 'lista')));





$fpcFrontendOptions = array(
                'lifetime' => 7200,
                'debug_header' => false,
                'regexps' => array(
                    '^/index/index/' => array('cache' => true)
                )
            );


            $fpcBackendOptions = array(
                'cache_dir' => 'tmp/'
            );
            $fullPageCache = new Zend_Cache_Frontend_Page($fpcFrontendOptions);
            $zcb = new Zend_Cache_Backend($fpcBackendOptions);
            $fullPageCache->setBackend($zcb);
            //echo "TEST CACHE";
            $fullPageCache->start();

//$controller->setControllerDirectory("../application/controllers");

$controller->setControllerDirectory(array(
            "default" => "../application/default/controllers",
            "bo" => "../application/bo/controllers"
            ));

$controller->throwExceptions(true); // should be turned on in development time 
// run!
$controller->dispatch();



?>

但是当我调用我的控制器时 eg. http://localhost/test/index.php/cp 我只想删除 index.php 文件。在 .htaccess 文件或 zend 框架的 index.php 文件中。

请给我任何建议。

【问题讨论】:

标签: php zend-framework


【解决方案1】:

Omega,是你的虚拟主机的文档根吗?或者是从你的虚拟主机中测试一个文件夹?

【讨论】:

  • Matt,我已经更新了我的问题.... 例如:localhost/test/html ----这是我的网站网址,其中 test 是我的文件夹----所有 zend 框架文件都保存在其中那里....但是我的 index.php 文件在 html 文件夹下....而且我也在下面显示 index.php 的代码....我的网站使用此链接成功运行"http://localhost/test/html"
【解决方案2】:

就像在 Zend 教程中一样。您需要在 Apache 中激活 mod_rewrite 并像这样添加虚拟主机:

<VirtualHost *:80>
  ServerName mypage.dev
  DocumentRoot /path/to/quickstart/public
  SetEnv APPLICATION_ENV "development"
  <Directory /path/to/quickstart/public>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

【讨论】:

    猜你喜欢
    • 2012-12-30
    • 2014-10-10
    • 2015-07-26
    • 2012-12-22
    • 2013-12-21
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多