views:

731

answers:

4
+3  Q: 

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?

A: 

Remember to change your RewriteBase.

Bill Karwin
+2  A: 

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

Rob Allen
A: 

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
gabrielk
A: 

I have my application on a shared server, and I'm having some troubles setting the .htaccess

I was able to redirect all the request from http://www.recursoshidricostdf.com.ar/siia to siia/public/index.php (Thanks Rob Allen). The problem I have now is that the path for the css, img, ico files is wrong.

My folder stucture is: /siia .htaccess index.php /application /docs /library /public /.htaccess

I created a index.php and .htaccess as Rob suggested in /siaa/

Thanks in advance Leandro

Leandro