开发者

Zend MVC - htaccess redirect

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 webmaster@billingsystem.localhost
    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 htt开发者_开发百科p://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?


I just went through something like this on a site. My solution was that I needed to use two .htaccess files on the domain. One in the root level of the site and another in the public folder.

So, the one at the root of the domain looks like this:

<Files .htaccess>
    order allow,deny
    deny from all
</Files>

Options +FollowSymLinks
RewriteEngine On

#Zend Rewrite Rules
RewriteRule ^(.*)$ /public/$1 [NC,L]

AddHandler php5-script .php

Within the public folder I have the following rules in place:

<Files .htaccess>
    order allow,deny
    deny from all
</Files>

RewriteEngine On

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

This seems to work well to get all content trafficking through the Zend framework.

Hope this is helpful. - liam


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 webmaster@billingsystem.localhost
    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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜