HTACCESS subdomain and environment ZEND - zend-framework

We're currently creating an application with ZEND that we'd like to be able to set the environments through a second parameter IN FRONT of the domain.
Something like this:
app.production.mysite.com
App would indicate the folder (mysite.com/app), production the environment and mysite our domain.

You can use apache2 aliases together with mod_rewrite rules in order to achieve that.
This is an example httpd.conf section which setup a root zend framework app in /var/rootapp, and 2 other separated ZF apps under app1 & app2 folders.
<Directory "/var/app1/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /app1
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</Directory>
<Directory "/var/app2/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /app2
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</Directory>
<VirtualHost *:80>
ServerName app.production.mysite.com
DocumentRoot /var/rootapp/public
Alias /app1 /var/app1/public
Alias /app2 /var/app1/public
</VirtualHost>

Related

Deployment Zend-framework2 on RHEL6.5

I've developed a web Zend-framework2 application on windows everything worked fine.
I want to deploy my project to my server on RHEL 6.5. I've tried everything but I can't do so.
This is my project structure
|--zend
|--config
|--data
|--module
|--Application
|--...
|--public
|--index.php
|--.htaccess
|--vendor
|--init_autoloader.php
This is the content of .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
This is the content of index.php
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server') {
$path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (__FILE__ !== $path && is_file($path)) {
return false;
}
unset($path);
}
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
my php version is 5.3,rewrite_mod is on
i've add virtualhost to the httpd.conf like so
<VirtualHost *:80>
ServerName zend.local
DocumentRoot /var/www/zend/public
<Directory "/var/www/zend/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
what should id do ?

htaccess issue after connecting domain to subfolder

I have a problem with .htaccess. I have a website in the main server folder and a domain that leads to it (adriatic.pl). No i have made a new version of the website and put it in "adriatic_new" folder. When i run adriatic.pl/adriatic_new/public everythig works fine, but when i connect the domain (adriatic.pl) directly to the "adriatic_new" folder I get "500 Internal Server Error".
I found that it may be .htaccess problem bo how to edit it to make it work?
It looks like this:
SetEnv APPLICATION_ENV development
Allow from all
DirectoryIndex main.php
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/static/index.html -f
RewriteRule ^/*$ static/index.html [L]
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}.html -f
RewriteRule .* static/%{REQUEST_URI}.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)/+$
RewriteRule ^.*$ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ main.php [NC,L]
php_flag magic_quotes_qpc off
php_flag register_globals off
Ok guys (and ladies?) - problem is solved.
All I had to do was to add "RewriteBase /" in my .htaccess. So simple yet so confusing and annoying. Thanks.

Mod rewrite virtual host and Zend

My Apache config:
DocumentRoot /var/www
<VirtualHost *:80>
Alias /T "/var/www/Test"
<Directory /var/www/Test>
Options Indexes FollowSymLinks MultiViews
#AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
SetEnv APPLICATION_ENV "development"
Alias /N "/var/www/NCAA/public"
<Directory /var/www/NCAA/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My .htacess file in /var/www/NCAA/public:
RewriteEngine On
RewriteBase /N/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I can go to files in localhost/T, but I get 404 for /localhost/N I get this in my apache log:
[Sun Nov 20 16:32:37 2011] [error] [client 127.0.0.1] File does not exist: /var/www/N,
so I'm not sure what I am doing wrong. I want 1 domain to be a regular domain with an alias and the other is a Zend app with a mod rewrute for the index.php
Thanks
Do you really need the NCAA app to be accessed under http://localhost/N? Is it acceptable to access it under a different url, like http://local.ncaa/?
If so, then a virtual host entry could look like:
<VirtualHost *:80>
DocumentRoot /var/www/NCAA/public
ServerName local.ncaa
SetEnv APPLICATION_ENV development
<Directory /var/www/NCAA/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then the standard ZF .htaccess can be used (no rewrite base required):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Rewrite problem, /controller/action instead of /folder/file.php

I have a script of calling KCFinder.
window.open('/kcfinder/browse.php?type=files', ...);
it must open a window which contains KCFinder, but when I click the "Browser" button, it generatates error:
"Uncaught exception
'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller
specified (kcfinder)' in
/home/vhosts/vonline_admin/library/Zend/Controller/Dispatcher/Standard.php
on line 248"
I understand this error. It says that controller "kcfinder not found", but kcfinder doesn't require a controller, it's simply a path. Strangely, I run the website successfully in local but when I put it on hosting, it failed.
I think it is related to rewrite problem or routing but I don't know how to fix it.
Vhost: /usr/local/apache2/conf/vhosts/something_admin.conf
ServerName admin.something.com
ServerAdmin foo#boo.com
DocumentRoot /home/vhosts/something_admin/www
SetEnv APPLICATION_ENV development
TraceEnable off
<Directory /home/vhosts/something_admin/www>
Options -Indexes -Includes -ExecCGI -FollowSymLinks
AllowOverride None
</Directory>
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|swf|txt|htm|html|xml)$
/index.php
.htaccess in www:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
The only difference I can see between your htaccess file and mine is in the RewriteRules; I have an asterisk:
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

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