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]
Related
Someone help me.
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
config file
$config['base_url_front'] = 'http://example.com;
$config['base_url'] = 'http://example.com';
$config['post_image_url'] = $config['base_url'].'assets/images/post_image/';
$config['post_video_url'] = $config['base_url'].'assets/images/post_video/';
$config['art_image_url'] = $config['base_url'].'assets/images/art_image/';
$config['media_video_url'] = $config['base_url'].'assets/images/media_video/';
$config['parent_folder_name'] = $_SERVER['DOCUMENT_ROOT'].'/';
directory structure
[![enter image description here][1]][1]
site available file config:
ServerAdmin webmaster#localhost
ServerName example.com
DocumentRoot /var/www/html/sourcedirectory
<Directory /var/www/html/sourcedirectory/>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
I would appreicate any advice... Thanks.
[1]: https://i.stack.imgur.com/yTGkX.png
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>
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.
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?
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.