John x
John x

Reputation: 4031

Redirect request to public directory zend

I have a sub domain to which i have deployed my zend application, the problem is it points to the directory say abc and i cannot get it changed to point it to public directory is there a way i can put a .htaccess file on the root which will redirect to the public directory? can it be done? is there another way i can get it done

my index.php inside public dir

<?php

// 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();

my .htaccess inside public dir

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

currently the directory structure looks like

/myroot
 -.settings
 -application
 -docs
 -library
 -public
 -tests
 -.buildpath
 -.proect
 -.zfproject.xml

Upvotes: 0

Views: 8874

Answers (2)

iveres
iveres

Reputation: 163

RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]

no errors and no problems..

Upvotes: 3

Adrian World
Adrian World

Reputation: 3128

I hope I get your domain setup correctly. If you have this setup

sub.domain.net --> /myroot

you will need an .htaccess in that (/myroot) folder because it is the base of your http requests. It should look like this

RewriteEngine On  
RewriteBase /public  
RewriteCond %{REQUEST_FILENAME} -s [OR]  
RewriteCond %{REQUEST_FILENAME} -l [OR]  
RewriteCond %{REQUEST_FILENAME} -d  
RewriteRule ^.*$ - [NC,L]  
RewriteRule ^.*$ public/index.php [NC,L]  

The RewriteBase directive should find all request in the RewriteCond and applies mainly to the first RewriteRule. It basically sets (rewrites) the relative root for all HTTP path request. The second RewriteRule finally triggers your application which is a local path. (I hope I am not wrong about this last rule. If that doesn't work try without the public. I can't test it but I had got an app to work like this a few years back.)

Upvotes: 1

Related Questions