Zend instance in a subfolder of another Zend - zend-framework

Hi i have a Zend installation in main domain.
Now i want to make a subfolder and run Zend for some testing purposes. I have copied all files from main site to subfolder named www2. But when i call the subfolder like domain.com/www2 i think the main Zend instance get invoked and produces a Message: Invalid controller specified (www2) error?
my .htaccess of main Zend is
SetEnv APPLICATION_ENV development
RewriteEngine on
RewriteCond %{REQUEST_URI} "/www2/"
RewriteRule (.*) $1 [L]
and Subfolder is like
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
What i am doing Wrong. I have full access to server.

in subfolder Zend in file application/Bootstrap.php add LIKE this:
protected function _initRoutes()
{
$this->bootstrap('frontcontroller');
/**
* #var Zend_Controller_Front $front
*/
$front = $this->getResource('frontcontroller');
/**
* #var Zend_Controller_Router_Rewrite $router
*/
$router = $front->getRouter();
$router->addRoute('www2',
new Zend_Controller_Router_Route(
'www2/:controller/:action',
array('controller' => 'index',
'action' => 'index'))
);
}
But may be you need another route...
UPD1:
first .htaccess like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/www2*
RewriteRule ^.*$ www2/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

You could create a subdomain www2.domain.com pointing the www2/public directory and restore all .htaccess files to their normal single-site state.
This way, the www2 copy is completely standalone app with the same url and file structure as the original www site.

Related

Custom routing logic and serving static content while having the document root in the parent of the public directory?

I extend Zend_Controller_Router_Route_Abstract in Zend Framework to add custom routing to my application. My match method return false in cases it identify that the request path isn't ones of the paths it must process. So with paths, like statics resources paths, my custom routing class return false and the default Module router take care of.
My problem is that all work fine as far I have the document root of my site pointing to my public directory. When I change the document root to the directory in witch public folder is (parent directory), the following error appear when try to request an static resource like http://mysite.com/css/global.css:
An error occurred Page not found Exception information:
Message: Invalid controller specified (css) Stack trace:
Stack trace: ....
Request Parameters:
array ( 'controller' => 'css', 'action' => 'global.css', 'module' => 'default', )
That is just part of the message, the other part is irrelevant.
My questions is, how can I solve this problem? How can I have my custom routing logic and serving static content while having the document root in the parent of the public directory?
Here the .htaccess I uses when document root isn't pointing inside public dir:
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]
You should not server static files from PHP. It means you should use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

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
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..
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.)

Zend Framework htaccess Backend / Frontend

In my current ZF project, I've two public access points (files) ready to handle & process coming requests, that's: index.php & admin.php
I need all URLs containing '/admin' to be routed to admin.php while any other URLs doesn't contain '/admin' to be routed to index.php
Knowing that default ZF htaccess contains the following rules:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
How this can be implemented?
I want to start by saying that I full heartedly agree with AurelioDeRosa. I do believe that routes will be a better choice. However that is your choice not mine and this .htaccess code should do the trick you want.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*(admin).*$ admin.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Note however that this script will catch anything that contains admin so it might break your frontend. for example, if you want to list all your users with administrative rights the url yoursite.com/users/listby/admin/ will redirect the request to admin.php, and so will urls like /administrator/ or /adminininini

deploying zend framework application in mediatemple GS

i am having trouble deploying my zend framework application to mediatemple GS hosting.
I uploaded my application folder to ~/domains and renamed it to mysite.net folder.
Inside it, i created a symbolic link html which points to public directory in zend framework application folder. But the application is not working so far. Generally, mediatemple points a host to ~/domains/host/html path so my domain mysite.net should point to ~/domains/mysite.net/html.
Am i doing something wrong or is there more to this ? I am getting a 403 error when trying to access mysite.net
Update: Following rewrite rules make the base url http://mysite.net loadable but controllers dont work now. accessing http://mysite.net/controller sends page not found error :S
SetEnv APPLICATION_ENV development
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]
Update: Its solved now. The trick is to add above .htaccess file to the application root folder and also keep the original .htaccess in public directory. Together they do wonders.
I've found the solution myself:
create a .htaccess file in application root folder:
SetEnv APPLICATION_ENV development
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]
Also keep the original .htaccess in the /public folder. I delete this at first which made things worse.

ISAPI ZEND url rewrite adding extra "/index.php/" into url

We recently reinstalled our web site on our server, the sys admin says it is an exact rebuild, and it indeed looks to me that it is, but there is something different going on. I did not originally develop the site, and those who did are no longer available.
urls for the admin site are now
//admin.site.com/index.php/schedules
and used to be, and should be
//admin.site.com/schedules
The extra index.php is getting inserted in the url. But all links within the admin site do not include the index.php so they do not work. If you insert the index.php into any url, it works. Where did this index.php come from and how do I eliminate it from the rewrite rules so the links will work.
This is what my httpd.conf file reads:
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.56
# turn on rewriting RewriteEngine On RewriteBase /
# for all files not found in the file system,
# reroute to "index.php" bootstrap script,
# keeping the query string intact.
RewriteCond %{HTTP_HOST} ^admin.site.com$
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^admin.site.com$
RewriteRule ^.*$ index.php [NC,L]
Thank you! Any help would be greatly appreciated.
You need to implement and enable ApacheModrewrite. And then put a .htaccess file in your admin.site.com folder
Its content will be :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]