.htaccess with virtual hosting zend framework 1 ubuntu

449 views Asked by At

I have setup an Ubuntu server that has virtual hosting, in the folder :/var/www/vhosts/dev.blla.com/httpdocs/src is the web application built with zend framework 1. The problem is that I have an .htaccess file that looks like below:

<VirtualHost dev.blla.com:80>
    ServerName   dev.blla.com
    DocumentRoot /var/www/vhosts/dev.blla.com/httpdocs

    RewriteEngine off

    <Location />
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </Location>
</VirtualHost>

The .htacess file is located in /var/www/vhosts/dev.blla.com/httpdocs, the web shows 500 Internal Server Error what am I doing wrong?

In an error log I have this line: /var/www/vhosts/dev.blla.com/httpdocs/.htaccess: <VirtualHost not allowed here, referer: http://dev.blla.com/

vhost file:

<VirtualHost *:7080>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
1

There are 1 answers

12
Panama Jack On BEST ANSWER

Your vhost file should look like this. Don't use location directive and especially to root /. You should be using Directory.

<VirtualHost dev.blla.com:80>
    ServerName   dev.blla.com
    DocumentRoot /var/www/vhosts/dev.blla.com/httpdocs

    <Directory "/var/www/vhosts/dev.blla.com/httpdocs">
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </Directory>
</VirtualHost>

These are the only context RewriteEngine will work. Location is not one of them. Restart apache after changes.

server config, virtual host, directory, .htaccess

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteengine

Edit: Apparently you have this in your .htaccess file. That will not work. This is supposed to be your vhost file as I mentioned above. The only thing allowed in .htaccess is this alone. VirtualHost and Directory can not be used in .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]

This also might help you.

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts