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

前端 未结 3 593
我在风中等你
我在风中等你 2021-01-07 09:19

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

--------------------------------------------------------------         


        
相关标签:
3条回答
  • 2021-01-07 09:40

    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

    0 讨论(0)
  • 2021-01-07 09:50

    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/

    0 讨论(0)
  • 2021-01-07 09:52

    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.

    0 讨论(0)
提交回复
热议问题