Running Zend Framework in a subfolder - Problems with default controller - zend-framework

I am starting a Zend application and I need to put it in a sub folder like this:
/subfolder
application
public
...
I did the following:
I set the base url in application.ini:
resources.frontController.baseUrl = "/subfolder"
I moved the .htaccess from the public folder directly into /subfolder, while changing the htaccess as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]
That's all I did. And everything works as expected. I can add controller blog with action view and can access it by calling:
/subfolder/blog/view
the url view helper and stuff work right too. The only thing that does not work is the default controller. So when I enter:
/subolder/
I get 403 (forbidden). If I enter
/subfolder/index
...it works. What am I missing?!
Thanks in advance!
teebee

you do not need to make any change in your zf public folder, just create an .htaccess file into the "/subfolder" directory with the following lines
# Rewrite rules
RewriteEngine on
RewriteRule (.*) ./public/$1

Replace
RewriteRule ^.$ public/index.php [NC,L]
with
RewriteRule ^.$ http://addressto/index.php [R=302,NC]
or
RewriteRule ^.*$ /public/index.php [NC,L]
i'm not sure if putting ZF folders other than public into publicly accessible folder is right.It will impose your site on security flaws. You must put ZF'S public folder' contents into your server`s public folder and put other folders into a non-publicly accessible folder.If you need more that one instance of your ZF application you may use Zend module system.Please refer to zend online documentation for more details.

Related

How to remove "public" from url using routeing in zend framework

An one issue in my zend, i write rule in .htaccess to remove "public" from url as following,
------------------------------------------------------------------------
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain-name.com/$ [OR]<br/>
ReWriteCond %{REQUEST_URI} !public/<br/>
ReWriteRule ^(.*)$ public/$1 [L]<br/>
------------------------------------------------------------------------
but there is ROUTE method in zend, i have use it for multiple language to set language code in url LIKE www.domain-name.com/en/ , using zend_controller_router_route_chain,
before this method implemented, my url is www.domain-name.com but
when i use this method in my zend project, may be it overwrites .htaccess rule of removing "public" from URL or something happen using same and "public" is displaying in url like www.domain-name.com/public.
so IS THERE ANY METHOD OR TRICK TO REMOVE PUBLIC FROM URL USING ANY METHOD OF ROUTE IN ZEND FRAMEWORK ???
Thanks,
MRJethva.
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/
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

Zend Framework in subdirectory

I'm banging over the wall with this...
I need to establish a zend framework application inside a subdirectory.
i.e. the domain is tricell.ss and I want to use tricell.ss/tricell as application main directory.
Whate've done:
I've setted up in my config (application.ini) the:
resources.frontController.baseUrl = "/tricell"
I've made another var in my config
baseUrl = "/tricell"
In my Boostrap I've got this:
$router = new Zend_Controller_Router_Rewrite();
$frontController->setRouter($router);
$frontController->setBaseUrl($this->config->baseUrl);
$frontController->dispatch();
In my layout I'm trying to display image with using:
$this->baseUrl('/img/btn.png')
Here are my vhost configuration:
<VirtualHost *:80>
DocumentRoot "/HTDOCS/tricell/tricell/public_html"
ServerName tricell.ss
RewriteRule ^$ [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?tricell.ss$
RewriteRule ^(/)?$ tricell [L]
</VirtualHost>
here is my .htaccess:
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]
The problem is when I'm trying to display image nothing happens. When I'm trying to get the image by URL:
http://tricell.ss//tricell/img/btn.png
I'm getting info about wrong controller. How I can make this right? I can (without any problems) make configuration for root domain like tricell.ss and then get image i.e. tricell/ss/img/btn.png, but I want to work on subdirectory, and I can't do that with images. What I am doing wrong here?
I think the easiest thing you can do to get this working is this:
Start with a fresh ZF project, or remove all of your zend routes, and any special configuration in .htaccess or httpd.conf/httpd-vhosts.conf that you created.
Get rid of the baseUrl options you set up in your config file.
Place the index.php file and the .htaccess file in your /HTDOCS/tricell/tricell/public_html/tricell folder.
Place the rest of your project (controllers, models, config etc) outside of your web root. In this example I will assume they are placed in /HTDOCS/tricell/tricell/zfproject.
Edit index.php and change:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// to:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../zfproject/application'));
Now your application will run with the base directory being yoursite.com/tricell
IndexController.php's URL is going to be http://yoursite.com/tricell/index
You do not need to do anything special to tell Zend your base URL is "tricell". Just make sure in your view scripts to use $this->baseUrl() for your paths so you don't need to worry about manually adding /tricell to the beginning of everything, and if you ever move your project to another directory/path, nothing needs to be changed to deal with the new paths.
I've just manage to resolve my issue... it's quite simple but I was very confused by all this rewriting rules.
As saying always tricell is confusing let's make some changes to that as well.
So to achive something like tricell.ss/sub I would need to:
Put my whole application inside /HTDOCS/tricell/tricell/sub
Change my vhost from this line: DocumentRoot "/HTDOCS/tricell/tricell/public_html" to: DocumentRoot "/HTDOCS/tricell/tricell/"
Insert yet another .htaccess in my /HTDOCS/tricell/tricell/sub directory:
RewriteEngine On
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /sub/ublic_html/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/sub/public_html/.$
RewriteRule ^(.)$ /sub/public_html/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public_html/.*$ /sub/public_html/index.php [NC,L]
This resolved my all issues.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} "/tour/"
RewriteRule (.*) /tour/index.php [L,END]
</IfModule>
The above code in the root folder domain.com/.htaccess worked for me. I placed it directly as the first thing in the htaccess before the "# BEGIN WordPress" parts.
having a Zend installation in the domain.com/tour/ subdirectory
wordpress running on the root domain.com/ level
The final knack was to have the RewriteRule point to the index.php of Zend if Request_URI matches /tour/

Zend Framework - do not treat /public/directory as a controller

Is it possible to request a directory over http in the Zend /public/ directory without it being treated as a controller?
Eg, I have a directory, /public/facebook/ that contains facebook app data but Zend is (as default expected behaviour) giving "facebook controller missing" error when I request http://mysite.com/facebook.
This is because the default RewriteRules provided with Zend are redirecting all requests to the Zend Framework Bootstrapper (index.php).
The best thing to do, IMHO, is to add an exception to this Rule. Then there's more than one way to do it. You could use RewriteCond (and for example avoid the general redirect for existing directory or files in /public). But you could maybe filter it in the RewriteRule expression as well. This is an example with exception in the RewritreRule, so withoutt RewriteCond:
RewriteRule !(public/facebook/(.*\.php))|(public/(.*\.pdf))|(externalauthent\.php)|(favicon.ico)|(images/(.*\.(ico|gif|jpg|png|bmp|JPG|JPEG|BMP|GIF|PNG)))|(css/(.*\.css))|(js/(.*\.*))$ /index.php [L]
If you have content in this url, ZF don't try to found facebook controller, You need add a folder named facebook, and a file index.php into this folder
This work for me:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/public_directory_name
RewriteRule ^.*$ index.php [NC,L]
Just replace 'public_directory_name' with the name of the directory you don't want Zend to treat as a controller.
Answered in a different worded question: htaccess - do not rewrite in this case

zend framework deployment in server

I have a server, where I have uploaded my work in zend framework(in a subdomain). the folder name is 'visit'.
So, When I go to: http://mysitename.com/visit, it shows a directory structure:
Parent Directory
application/
docs/
library/
nbproject/
public/
tests/
But when I go to: http://mysitename.com/visit/public, i get the index page of my project.
But I want to get my index page , when I type: http://mysitename.com/visit
can you please give me the correct htaccess it need?
Also, these other approaches to deploying in shared hosting can help:
Zend Framework on shared hosting
http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/
http://www.ttech.it/en/article/2010/03/zend-framework-all-projects-files-on-document-root/
In particular, an answer by tharkun led me to write it up in more detail in a blog post.
You can do this with the following rule set, which is in part a partially modified version of the one described in the documentation.
.htaccess file in /visit:
RewriteEngine on
# Guard against people visiting /public/ directly
RewriteCond %{THE_REQUEST} ^[A-Z]\s/visit/public/
RewriteRule ^public/(.*)$ /visit/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
# Make sure we've rewritten to the ./public/ directory already
RewriteCond $0 ^public/
RewriteRule ^.*$ - [NC,L]
# The index file is now at /visit/public/index.php
RewriteRule ^.*$ /visit/public/index.php [NC,L]

Zend and modrewrite not working together properly

I'm setting up a Zend application, and went through the basic steps of setting up modrewrite on my development station, and writing an .htaccess file (shown below). Now, when I go to the root of my project, Zend works properly, calling the controller and displaying the appropriate page.
However, when I call any controller, I would expect it to redirect to the same index.php file, which would in turn direct it to the appropriate controller and action (e.g. myurl/controller/action would be read by myurl/index.php which would then redirect to the action appropriately).
I suspect that the issue is somehow related to how I've set up my .htaccess file, since calling the base url does work properly. But I haven't been able to figure out what's wrong. Does anyone have a suggestion?
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Okay, here's what it was.
My DOCUMENT_ROOT is set to /var/www while my application is running out of /var/www/app1 with everything set up in there. Because of the line RewriteBase / it was redirecting to the DOCUMENT_ROOT instead of to the APPLICATION_ROOT. I fixed it by changing that line to:
RewriteBase /app1
and now everything works perfectly.