0

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]
7
  • can you show us the .htaccess file in the public directory? You should have one Commented Aug 13, 2014 at 15:18
  • have you activated mod_rewrite? run sudo a2enmod rewrite Commented Aug 13, 2014 at 15:21
  • I have edited the question so you can see the htaccess file content Commented Aug 13, 2014 at 15:30
  • see this : stackoverflow.com/questions/13538543/… Commented Aug 13, 2014 at 15:55
  • Pretty much followed that but still no change Commented Aug 13, 2014 at 16:15

2 Answers 2

1
  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]
    
Sign up to request clarification or add additional context in comments.

Comments

0

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]

2 Comments

This has done something like it seems the images have started to show up however all the styles/scripts etc are still not :S
We have a little progress here i have sorted the issue out with the public folder routing with the images/css/js. The only issue now is when i click out side 'gc.dev/' for example 'gc.dev/blog/ it wont find anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.