Zend Framework on shared hosting

后端 未结 12 1416
孤独总比滥情好
孤独总比滥情好 2020-12-04 17:01

I\'m new to Zend Framework. I would like to know how to implement zend framework on a shared hosting. Because of the zend framework folder structure all view files are put i

相关标签:
12条回答
  • 2020-12-04 17:35

    Include this .htacces file under your base path (that is /../public):

    RewriteEngine On
    
    # Exclude some directories from URI rewriting
    #RewriteRule ^(dir1|dir2|dir3) - [L]
    
    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]
    

    And leave the .htaccess that was under the publc directory where it was.

    So you will have 2 .htaccess files, one under the public directory (the ordinary one from Zend Framework documentation) and second one under your base path (the one I posted above).

    0 讨论(0)
  • 2020-12-04 17:39

    i think the best way is to remove the .htaccess from the public directory (Zend Framework Directory structure) , and put it with the following content into your "root" directory :

     
    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]

    0 讨论(0)
  • 2020-12-04 17:39

    The answer from ArneRie did not work for me and I finally ended up using Lorenzo Albertons solution. Hope this is helping others to get a faster solution.

    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]
    
    0 讨论(0)
  • 2020-12-04 17:40

    I've been in the same situation and have put the zend libraries under a folder under public like 'src' - and use an .htaccess Deny from All. You'll have to juggle a couple paths, but it works fine.

    0 讨论(0)
  • 2020-12-04 17:44

    I suggest the simpliest: Develop your apps in a way where index.php is in your root (even better - always define PUBLIC_PATH - dirname(__FILE__); in your index.php and make links relative to this constant). Along with the application and library folders. You can easily make them unaccessible from outside using deny from all in .htaccess.

    The PUBLIC_PATH constant also helps when your public is not public. (public html or /public html/www (in my case))

    0 讨论(0)
  • 2020-12-04 17:47

    Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.

    Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:

    Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.
    
    Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:
    
     <VirtualHost *:80>
         ServerName zf2-tutorial.localhost
         DocumentRoot /path/to/zf2-tutorial/public
         SetEnv APPLICATION_ENV "development"
         <Directory /path/to/zf2-tutorial/public>
             DirectoryIndex index.php
             AllowOverride All
             Order allow,deny
             Allow from all
         </Directory>
     </VirtualHost>
    
    Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1.

    Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1.

    0 讨论(0)
提交回复
热议问题