Sunday, June 10, 2012

Zend and .htaccess


My default 'zend' app has this default structure




/zend + webroot
/application
/config
/library
/public
.htaccess
index.php



and the default .htaccess redirects the various controller/action details via ./public/index.php




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



I use this default url to access the app




http://domain/index.php



I've now moved to a shared host, where the webroot is above the 'zend' root.




/webroot
/zend
/application
/config
/public
index.php
.htaccess



but i can only access my app via this URL




http://domain/zend/public/index.php



i want to be able to use




http://domain/zend/index.php



and have .htaccess redirect.



and i'm wondering how i can tweak the .htaccess file to redirect the URL requests. I read this tutorial but i didn;t work for me




/webroot
/zend
.htaccess
/application
/config
/library
/public
index.php



This is the .htaccess content in this case




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]



Can anybody spot anything?


Source: Tips4all

3 comments:

  1. Create zend/index.php containing this code:

    <?php include 'public/index.php';


    Now create zend/.htaccess containing this code:

    SetEnv APPLICATION_ENV development

    RewriteEngine On
    RewriteRule .* index.php


    Make sure that your images/css/js files are all within zend/public/ and do not remove the zend/public/.htaccess file :)

    Don't forget that the request's baseUrl doesn't include '/public', so you'll need to add it yourself when you reference public facing files.

    Regards,

    Rob...

    ReplyDelete
  2. Remember to change your RewriteBase.

    ReplyDelete
  3. Most shared hosts I've used still allow you to upload files outside the web root. For example,

    /home/{username}/webroot/


    ...you can still upload to /home/{username}/ like:

    /webroot
    index.php
    .htaccess
    /application
    /config


    Then in your bootstrap, just replace public with webroot, or if you have ssh access delete the existing webroot and replace it with a symbolic link to the zend public directory, like:

    rm -f webroot
    ln -s public webroot

    ReplyDelete