views:

211

answers:

2

All, My Zend framework Application structure is like this:

billingsystem
 -application
 -design
    --css
        --struct.css
    --icons
    --styles
    --images
    --js
       --common
       --thirdparty
 -public
    --index.php
    --.htaccess
 -library
    -- Zend

My Apache VHost is like this:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /opt/lampp/htdocs/xampp/billingsystem
    ServerName billingsystem
    ErrorLog logs/billingsystem.localhost-error.log
    CustomLog logs/billingsystem.localhost-access.log common
    <directory /opt/lampp/htdocs/xampp/billingsystem>
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
    </directory>
</VirtualHost>

My .htaccess in public folder is like this:

RewriteEngine   on
# The leading %{DOCUMENT_ROOT} is necessary when used in VirtualHost context
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

If I browse to http://billingsystem, it shows the apache directory path on the browser. If I go to http://billingsystem/public, the application executes code on the web page. Is it possible to create or modify .htaccess file such that, when a user browses to http://billingsystem, it should redirect the browser to http://billingsystem/public and execute the code instead of showing the directory structure?

Also, how can I redirect the user to "public" directory when he tries to access any folder through the browser?

+1  A: 

To directly answer your question you can place a .htaccess directly in the billingsystem folder with a rewrite rule:

RewriteRule ^(.*)$ /public/$1 [NC,L]

However, your setup should look more like the following:

File System

billingsystem
 -application
 -design
 -public
    --index.php
    --.htaccess
 -library
    -- Zend

Virtual Host

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /opt/lampp/htdocs/xampp/billingsystem/public
    ServerName billingsystem
    ErrorLog logs/billingsystem.localhost-error.log
    CustomLog logs/billingsystem.localhost-access.log common
    <directory /opt/lampp/htdocs/xampp/billingsystem/public>
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
    </directory>
</VirtualHost>

.htaccess

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

RewriteRule ^.*$ index.php [NC,L]

Now the question that remains is that i know you have stuff in you design directory that aparently needs to be web accessible... Can you elaborate on the directory structure in design so that we can figure out what you need to do (if anything) to properly access the various types of files contained in it?

prodigitalson
Basically, the DocumentRoot should be moved to the public folder..
Chacha102
Please see the directory structure edit in my post. Now, I tried to move design folder into public folder.. My header.phtml file in /application/view/scripts folder tries to access it using /design/css/struct.css.. It didn't work for me this way..
Vincent
Did you remove the `%{DOCUMENT_ROOT}` from the rewrite rules like in my example? Also what happens if you point your browser at `http://www.billingsystem/design/struct.css` what kind of error do you get?
prodigitalson
Also you might want to use the `baseUrl()` function to generate that css path as well if youre currently hard coding it.
prodigitalson
Yes..I removed the %{DOCUMENT_ROOT} as you suggested. When I browse to that css like you suggested, it redirects me to a custom error controller telling page not found..
Vincent
Ok easy stuff first - You did restart Apache after modifying the VirtualHost correct? Are owner, group and their respective permissions for `/design/css/struct.css` **identical** to those for `/index.php`? How are you including the stylsheet and what is the code you are using (ie. are you using the `headLink` helper, hard coding the entire tag, echoing an `@import` directive, etc..)?
prodigitalson