【问题标题】:.htaccess with virtual hosting zend framework 1 ubuntu.htaccess 与虚拟主机 zend 框架 1 ubuntu
【发布时间】:2015-06-22 17:26:25
【问题描述】:

我已经设置了一个具有虚拟主机的 Ubuntu 服务器,在文件夹 :/var/www/vhosts/dev.blla.com/httpdocs/src 中是使用 zend 框架 1 构建的 Web 应用程序。 问题是我有一个如下所示的 .htaccess 文件:

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

.htacess 文件位于/var/www/vhosts/dev.blla.com/httpdocs,网络显示500 Internal Server Error 我做错了什么?

在错误日志中我有这一行:/var/www/vhosts/dev.blla.com/httpdocs/.htaccess: &lt;VirtualHost not allowed here, referer: http://dev.blla.com/

虚拟主机文件:

<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

【问题讨论】:

  • 检查以确保您已为 apache 启用 Rewrite 模块
  • a2enmod rewrite 检查是否启用,返回 Module rewrite already enabled
  • 尝试删除显示 RewriteEngine Off 的行,以确保。否则尝试更简单的重写。类似RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [NC,L]
  • 我删除了 RewriteEngine 关闭相同的结果。我应该把以下内容放在哪里: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [NC,L]
  • 是的,我们需要更多关于您的设置的详细信息。如果您收到 Nginx 和 apache 错误,您可能正在使用代理服务或专门设置

标签: php apache .htaccess zend-framework virtual-hosts


【解决方案1】:

您的虚拟主机文件应如下所示。不要使用location 指令,尤其是root /。你应该使用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>

这些是 RewriteEngine 唯一可以工作的上下文。 Location 不是其中之一。更改后重新启动 apache。

server config, virtual host, directory, .htaccess

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

编辑:显然你的 .htaccess 文件中有这个。那不管用。如上所述,这应该是您的虚拟主机文件。 .htaccess 中唯一允许的就是这个。 VirtualHost 和 Directory 可以在 .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]

这也可能对您有所帮助。

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

【讨论】:

  • 我完成了上述所有操作,但仍然收到 500 Internal server error,我还检查了 error_log 我收到此错误 /var/www/vhosts/dev.blla.com/httpdocs/.htaccess : dev.blla.com
  • 等等,这是在您的 .htaccess 文件中吗?这应该是您的虚拟主机文件。
  • 是的,它在 .htaccess 文件中,我应该把它放在哪里?
  • 虚拟主机文件在哪里?
  • 我改变了它,并重新启动了 apache 服务,现在登录页面正在工作,但我得到的其他页面不是:未找到在此服务器上找不到请求的文档。