Apache virtual host on a specific directory - zend-framework

I need my site to have a virtual host on a specific directory for my zend application. When user enters www.example.com it should go to normal document root but when user navigates to www.example.com/cms it should go to /var/www/cms/public which its .htaccess file is like this:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
On localhost I added this lines to /etc/apache/httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www/cms/public"
ServerName persian_literature
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/var/www/cms/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now http://localhost/ goes to /var/www/cms/public and every thing works. My question is how should I change change above code, to force http://localhost/ to be the normal directory root (so I could use other applications) and http://localhost/cms to be the virtual host?

A virtual host is done at the hostname/domainname level, not at a directory level. You can use an alias to point the URI /cms to some other directory on your server by putting
Alias /cms /var/www/cms/public
in a .conf file (this will not work in .htaccess)

Maybe a symlink (symbolic link)? You still should have the entry of course. And you'll have to put in the config (vhost config I think, maybe .htaccess) that apache should follow the symlink.

Related

Powermail (7.4.0) default Captcha keeps failing with TYPO3 9.5.7

I am trying to configure captcha field with powermail. It always throwing error Captcha: Falscher Captcha Code eingetragen, bitte erneut versuchen!, I tried to investigate the causes of the issue. I found if I remove below rewrite rule from .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
...then it's working correctly and form submission will succeed. But, this will lead you to another problem. As rewrite rule above redirect you to index.php if the file/symlink/directory does not exist, So this won't work. Now, your home page will work fine but inner pages will lead you to 404 error.
See:
Here is my apache configuration for virtual host:
<VirtualHost *:443>
ServerName www.relaunch.typo-site.de
ServerAlias relaunch.typo-site.de
<Directory "/var/www/html/relaunch">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Can anyone help me with this? I found a similar open issue at the Github repository.

HTACCESS subdomain and environment ZEND

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>

Zend Framework in subdirectory

I'm banging over the wall with this...
I need to establish a zend framework application inside a subdirectory.
i.e. the domain is tricell.ss and I want to use tricell.ss/tricell as application main directory.
Whate've done:
I've setted up in my config (application.ini) the:
resources.frontController.baseUrl = "/tricell"
I've made another var in my config
baseUrl = "/tricell"
In my Boostrap I've got this:
$router = new Zend_Controller_Router_Rewrite();
$frontController->setRouter($router);
$frontController->setBaseUrl($this->config->baseUrl);
$frontController->dispatch();
In my layout I'm trying to display image with using:
$this->baseUrl('/img/btn.png')
Here are my vhost configuration:
<VirtualHost *:80>
DocumentRoot "/HTDOCS/tricell/tricell/public_html"
ServerName tricell.ss
RewriteRule ^$ [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?tricell.ss$
RewriteRule ^(/)?$ tricell [L]
</VirtualHost>
here is my .htaccess:
SetEnv APPLICATION_ENV development
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 problem is when I'm trying to display image nothing happens. When I'm trying to get the image by URL:
http://tricell.ss//tricell/img/btn.png
I'm getting info about wrong controller. How I can make this right? I can (without any problems) make configuration for root domain like tricell.ss and then get image i.e. tricell/ss/img/btn.png, but I want to work on subdirectory, and I can't do that with images. What I am doing wrong here?
I think the easiest thing you can do to get this working is this:
Start with a fresh ZF project, or remove all of your zend routes, and any special configuration in .htaccess or httpd.conf/httpd-vhosts.conf that you created.
Get rid of the baseUrl options you set up in your config file.
Place the index.php file and the .htaccess file in your /HTDOCS/tricell/tricell/public_html/tricell folder.
Place the rest of your project (controllers, models, config etc) outside of your web root. In this example I will assume they are placed in /HTDOCS/tricell/tricell/zfproject.
Edit index.php and change:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// to:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../zfproject/application'));
Now your application will run with the base directory being yoursite.com/tricell
IndexController.php's URL is going to be http://yoursite.com/tricell/index
You do not need to do anything special to tell Zend your base URL is "tricell". Just make sure in your view scripts to use $this->baseUrl() for your paths so you don't need to worry about manually adding /tricell to the beginning of everything, and if you ever move your project to another directory/path, nothing needs to be changed to deal with the new paths.
I've just manage to resolve my issue... it's quite simple but I was very confused by all this rewriting rules.
As saying always tricell is confusing let's make some changes to that as well.
So to achive something like tricell.ss/sub I would need to:
Put my whole application inside /HTDOCS/tricell/tricell/sub
Change my vhost from this line: DocumentRoot "/HTDOCS/tricell/tricell/public_html" to: DocumentRoot "/HTDOCS/tricell/tricell/"
Insert yet another .htaccess in my /HTDOCS/tricell/tricell/sub directory:
RewriteEngine On
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /sub/ublic_html/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/sub/public_html/.$
RewriteRule ^(.)$ /sub/public_html/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public_html/.*$ /sub/public_html/index.php [NC,L]
This resolved my all issues.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} "/tour/"
RewriteRule (.*) /tour/index.php [L,END]
</IfModule>
The above code in the root folder domain.com/.htaccess worked for me. I placed it directly as the first thing in the htaccess before the "# BEGIN WordPress" parts.
having a Zend installation in the domain.com/tour/ subdirectory
wordpress running on the root domain.com/ level
The final knack was to have the RewriteRule point to the index.php of Zend if Request_URI matches /tour/

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?

404 error for mod_rewrite using SSL and MAMP

I am building an app in Zend Framework at the moment and testing it all locally. I have Mamp Pro as my web server and I have a self-signed SSL which all seems to work. My problem comes when I try to do mod_rewrite - I just get 404 pages.
The way I have things set up (which may not be the best way...)
In Mamp I have 2 virtualhosts set up both pointing to the same web directory (webroot/public/):
secure.myapp.com
myapp.com
In my public directory is my index.php file and my .htaccess file. The contents of the .htaccess file are:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
When I visit http://myapp.com everything routes as it should using the mod_rewrite. But when I go to https://secure.myapp.com the index page is fine, but URL routing stops working and it appears to be that the .htaccess file is being ignored.
In my ssl.conf I have the following:
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost _default_:443>
SSLEngine on
DocumentRoot "/webroot/public"
ServerName secure.myapp.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>
Does anybody have any ideas on this? I'll be sooooo appreciative of the help as it's seriously hindering my development!
Well I'm pretty sure that I have got this working. Basically, a big problem I had is that Mamp does not store vhosts.conf as an accessible file. Instead this is an aliased application file.
I think what happens is that the virtualhosts are all dynamically created all on the standard http port, in my case 80. However I needed to be able to access the port 433 vhost config to enable FileInfo. So my workaround is to ditch my .htaccess file and stick the following ALL into my ssl.conf file.
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost mysite.com:443>
SSLEngine on
DocumentRoot /webroot/secure
ServerName mysite.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
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]
RewriteLog /Applications/MAMP/logs/ssl_rewrite_log
RewriteLogLevel 3
</IfModule>
</VirtualHost>
</IfModule>
I had to add DOCUMENT_ROOT in front of my file and directory checks, and a forward slash in front of index.php. If I could have put this into a "Directory" then I think I could have avoided these changes, but Apache won't restart when I add this parameter.
The only thing I didn't try was adding the info to MAMP's httpd.conf, but I have a feeling the same restrictions may be in place.