为Zend应用程序设置vhost

时间:2014-08-13 15:15:14

标签: php zend-framework zend-framework2 config vhosts

我目前正在接管PHP Zend项目,我在本地计算机上的mamp中设置vhost时遇到问题。我有它工作到一定程度,这意味着它进入索引页面并执行一些PHP,但是没有链接工作,也没有找到路径文件夹文件(css,js和图像),这是我背后的痛苦。我之前从未与Zend合作过,因此我不知道我是否遗漏了一些东西。

这是我项目的虚拟主机设置......

<VirtualHost *:80>
DocumentRoot "/Users/john/Sites/application-website/public/"
ServerName gc.dev
#RewriteEngine on
<Directory "/Users/john/Sites/application-website/public/">
    DirectoryIndex index.php
    AllowOverride All
    Order deny,allow
    Allow from All
</Directory>

如果任何人有任何想法,那将是一个很大的帮助,请提前感谢你。

htaccess in public /

       # Enable rewrite engine
       RewriteEngine On
       RewriteBase /

       # The following rule tells Apache that if the requested filename
       # exists, simply serve it.
       RewriteCond %{REQUEST_FILENAME} -s [OR]
       RewriteCond %{REQUEST_FILENAME} -l [OR]
       RewriteCond %{REQUEST_FILENAME} -d
       RewriteRule ^.*$ - [NC,L]

       # Redirect to www
       RewriteCond %{HTTP_HOST} !^$
       RewriteCond %{HTTP_HOST} !^www\. [NC]
       RewriteCond %{HTTPS}s ^on(s)|
       RewriteRule . http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

       # Remove trailing slash
       RewriteCond %{HTTPS}s ^on(s)|
       RewriteRule ^(.*)/$ http%1://%{HTTP_HOST}/$1 [R=301,L]

       # Redirect index.php to /
       RewriteCond %{HTTPS}s ^on(s)|
       RewriteRule ^index.php$ http%1://%{HTTP_HOST}/ [R=301,L]

       RewriteRule ^(.*)$ index.php [NC,L]

2 个答案:

答案 0 :(得分:1)

  1. 确保您的httpd.conf文件
  2. 上通常在Apache上启用了mod_rewrite
  3. 以下虚拟主机 -

    <VirtualHost *:80>
        DocumentRoot /Users/john/Sites/application-website/public
        ServerName gc.dev
        <Directory /Users/john/Sites/application-website/public>
            DirectoryIndex index.php
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    
  4. 您的.htaccess如下所示(应位于public / .htaccess) -

    RewriteEngine On
    # The following rule tells Apache that if the requested filename
    # exists, simply serve it.
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    # The following rewrites all other queries to index.php. The
    # condition ensures that if you are using Apache aliases to do
    # mass virtual hosting, the base path will be prepended to
    # allow proper resolution of the index.php file; it will work
    # in non-aliased environments as well, providing a safe, one-size
    # fits all solution.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
    

答案 1 :(得分:0)

我想,您需要在.htaccess文件中添加以下行。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [NC,L]

这意味着,使用您的代码 -

# Enable rewrite engine
RewriteEngine On
RewriteBase /

# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# Redirect to www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule . http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Remove trailing slash
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^(.*)/$ http%1://%{HTTP_HOST}/$1 [R=301,L]

# Redirect index.php to /
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^index.php$ http%1://%{HTTP_HOST}/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [NC,L]