How to remove “public” from url using routeing in zend framework

我的未来我决定 提交于 2019-12-01 01:08:18

The following works for me using ZF2.2

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

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

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

SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteRule .* index.php

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');
} ?>

Enjoy!

Reference: http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/

drew010

Yes, and you don't need Zend_Route. Delete the public folder and put the Zend Framework files from it (index.php, .htaccess, etc) in your root directory (e.g. htdocs). You can place the application folder and other Zend Framework files outside of your web root where they cannot be accessed over HTTP.

All you need to do is edit index.php and change the APPLICATION_PATH to the correct path. This way your Zend Application will run from your root directory and you won't need to use mod_rewrite to hide the public folder.

See the last part of this answer for a similar example.

zf2 and zf3 remove Public from URL

create index.php and .htaccess add file in root of project

add the line in index.php include_once("public/index.php");

and in .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

after that go to following path

Module->application(module name)->view->layout->layout.phtml change css and js path add public in path

before

->prependStylesheet($this->basePath('css/bootstrap.min.css'))

->prependFile($this->basePath('js/bootstrap.min.js'))

after

->prependStylesheet($this->basePath('public/css/bootstrap.min.css'))

->prependFile($this->basePath('public/js/bootstrap.min.js'))

also in image path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!