John williams
John williams

Reputation: 731

Setting up vhost for Zend application

I am currently taking over a PHP Zend project and i am having trouble setting the vhost up for it in mamp on my local machine. I have it working to an extent, meaning it going to the index page and executes some PHP, however non of the links are working nor is it finding the rout folder files (css, js and images) which is a pain in my backside. I have never worked with Zend before so i am unaware if i am missing something out.

Here is my vhost settings for the project...

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

If any one has any ideas it would be a great help, thank you in advance.

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]

Upvotes: 0

Views: 74

Answers (2)

Rahul Datta Roy
Rahul Datta Roy

Reputation: 160

  1. Make sure you have mod_rewrite enabled on Apache usually on your httpd.conf file
  2. The virtual host to the following -

    <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>
    
  3. Your .htaccess looks like the following (should be located at 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]
    

Upvotes: 1

prava
prava

Reputation: 3986

I guess, you need to add the following lines in your .htaccess file.

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

That means, with your code -

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

Upvotes: 0

Related Questions