views:

119

answers:

4

By default my script is accessible by using this url http://localhost/myscript/public/. But i need to access it by this url http://localhost/myscript/. How can i do this in Zend Framework.

A: 

The "public" folder is an important key feature of the Zend Framework because it confines Apache to only read files in that directory and, if used properly, would keep all your other code outside public visibility. If you are indeed putting your entire application up and you have to do /public/index.php to get where you want to go, you should be aware of this.

Typically, in a shared hosting configuration, you will have a public folder for your site and you separate your public folder from the rest of your application. Say for instance you have a "public_html" folder in your directory, and that is the visible folder for your domain. Then, following that logic, instead of putting everything you wanted into your home directory, you "install" your application into a custom made sub-directory called "zend_app". You would copy the files from "public" into the "public_html" folder, copy the rest of the files into the "zend_app" folder and customize your index.php file apprioriately, for example:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../zend_app/application'));

Most of the other zend configuration is derived from that definition so it's fairly safe to build from that. If you keep that in mind when configuring your application, you can help maintain this portability. In theory, using this, you should be able to construct a configuration that would work for your needs.

JapanPro
this is not a soloution for his question...
zolex
the problem may persist coz major hosting provider provide public_html or public as root directory?
JapanPro
well, in general the url a zend application is called with, must not have any impact on it's functionality and look. i achieve this by setting the so called base-url in the config for mandatory use in the hole application. depending on the application envirionment the base url may then vary from his development machnine with "/myscript/public/" over stuff like staging and testting and typically "/" on a production machine as well as otehr developers with all individual setups.
zolex
A: 

just put all files from the public folder into the root folder.

then open the index.php or bootstrap.php, where ever you have this code

set_include_path(‘.’
        . PATH_SEPARATOR . get_include_path()
        . PATH_SEPARATOR . ‘../library’
        . PATH_SEPARATOR . ‘../application/classes/’
        . PATH_SEPARATOR . ‘../application/models/’

and change it to this one

set_include_path(‘.’
        . PATH_SEPARATOR . get_include_path()
        . PATH_SEPARATOR . ‘library’
        . PATH_SEPARATOR . ‘application/classes/’
        . PATH_SEPARATOR . ‘application/models/’

but check other pathes too, like this one.

require_once 'Zend/Controller/Front.php';

Got this tutorial from this page :) http://www.fincha.com/blog/2010/tutorial-zf-public-verzeichnis-umgehen-nicht-verwenden/

Its in German...

Fincha
thanks bro, it works.
Imran Naqvi
WOW THIS IS MADNEDSS PURE!!!! DO NOT DO THIS, THIS WILL CAUSE MANY MANY SECURITY LEAKS!!! see my answer for a proper soloution
zolex
@zolex yes it does, but on my host I can't use directrly the public folder... so I have to use it this way. or if you have 2 application first one is domain.com/first/ and second domain.com/second, how you gonna do this???
Fincha
just configure apache properly ^^
zolex
this is no problem to do this on a local server, but not every "public" server let you do this...
Fincha
@Fincha: why should you want to use such a great framework on such a bad server which does not allow proper configuration?... change your provider ^^
zolex
A: 

Create in public/ .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Alexander.Plutov
This won't remove /public Actually this is the default .htaccess from ZF...
Keyne
idd this won't help
zolex
A: 

simply create a virtualhost using your webserver and configure it to use the folder "public" as the document-root and you'll be fine and secure.

zolex
How to do this?
mrNepal