Reposition public folders in a Zend_Framework project?

I want my public_html folder on my server to be a shared folder in my zend project. Do you guys know how I can do this? Now I have to browse my site using domain.com/public

I tried changing the index.php file to this (changed directories)

// Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . 'application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . 'library'), get_include_path(), ))); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap() ->run(); 

But that does not work. Any idea how I can fix this?

Basically, I want the directory structure to look like this:

 public_html/ ----application/ ----library/ ----index.php 

Or is there any other way to achieve this? I want "public" to go away from my url.

Any ideas?

+6
source share
3 answers

if your .htaccess is configured correctly, you don’t have to worry about people getting into your library folder, simple rewrite rules can prevent this.

Below is what ive used to get rid of the shared directory on my index.php

 $path = realpath(dirname(__FILE__)); $dirs = array( $path . '/library', get_include_path() ); $includes = implode(PATH_SEPARATOR, $dirs); set_include_path($includes); defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application')); defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); require_once 'Zend/Application.php'; $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); 

and this is my .htaccess

 <IfModule mod_rewrite.c> Options +FollowSymLinks Options -Indexes RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule .* - [L] RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule \.svn/.* index.php [L] RewriteRule ^.*$ index.php [NC,L] </IfModule> 
+4
source

This is the wrong approach! The reason we have a shared folder and almost everything else on the same level is security! We do not want to have our libraries and application code in our shared folder!

The only thing you need to change is setting your vhost server (apache) to point to your shared folder as the document root.

 <VirtualHost *:80> DocumentRoot /path/to/your/public/folder ServerName domain.com <Directory path/to/your/public/folder> AllowOverride All </Directory> </VirtualHost> 
+2
source

This post offers one fairly simple approach (essentially, delete public and push all ZF files into a subfolder), but it also refers to several other approaches.

In particular, the comments on this post suggest that you can simply modify the .htaccess file in the root of your subdomain to send all requests to a shared folder:

 RewriteEngine on RewriteRule ^.* /public/$0 [L] 

Then in the public folder you save the .htaccess standard. In the worst case, you should also set the baseUrl application during Bootstrap , possibly through configuration.

+1
source

Source: https://habr.com/ru/post/886482/


All Articles