1

I developed a project on Zend Framework on Ubuntu. I created a virtual host on my local machine for testing. It is working perfectly on my local machine. This is the entry for virtual host on local machine.

<VirtualHost *:80>
    ServerName example.dev
    DocumentRoot /var/www/example/public/
    <Directory /var/www/example/public/>
        AllowOverride All
    </Directory>
</VirtualHost>

Problem:

My problem is that when I purchased domain(example.com) name and hosting they gave me following ftp directory to upload my content.

example.com is pointing to /www.example.com/web/content

But I need example.com to point/www.example.com/web/content/public

I asked them to solve it but they told it is impossible. Is there any programing/configuration solution of this.

Thanks

Edit:

I have already following .htaccess in /www.example.com/web/content/public

SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Student
  • 1,863
  • 9
  • 37
  • 50
  • I'm sure there are workarounds for this, and I'm sure some will come up. In general though, web hosting with no possibility to have directories outside the web root is not great. Depending on what their other features are, it would make me think about looking for another provider – Pekka Dec 07 '11 at 10:49
  • @Pekka: Thanks. If I put an **index.php** file `/www.example.com/web/content` and redirect it to `/www.example.com/web/content/public` in that **index.php**. Is it a good solution and will it work ? – Student Dec 07 '11 at 10:54
  • I'm not familiar enough with Zend MVC to answer that. I guess you should be able to change the .htaccess file in your project so it does the redirection internally, but to the outside, `public/` remains invisible. I'm sure there exist resources on that but I don't know where – Pekka Dec 07 '11 at 10:56
  • I already have **.htaccess** file in `/www.example.com/web/content/public`. This **.htaccess** file is used to change `example.com/index.php/person/profile` to `example.com/person/profile`(for example). – Student Dec 07 '11 at 10:59
  • See http://stackoverflow.com/a/3765443/131824 for a list of approaches to this common problem. – David Weinraub Dec 08 '11 at 11:31
  • I found my solution using a way in this question: http://stackoverflow.com/questions/8441133/zend-project-on-shared-hosting/8457589 – Student Dec 10 '11 at 15:32

3 Answers3

3

Depending on the web server they use and the configuration they have you may be able to override some of the configuration, for example, you can change document root with apache rewrite rules with a .htaccess file like this one to put under the root of /www.example.com/web/content

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteRule ^$ /public/index.php [L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]
Jean-Christophe Meillaud
  • 1,961
  • 1
  • 21
  • 27
  • Good answer but I don't recommend putting it in the .htacess as it's a performance killer. The rules written in the .htaccess file can't be cached by apache, the server has to scan the file for every single request.If you move the .htaccess rules to your virtual host configuration file, the rules will be cached and apache performance will improve. – Flukey Dec 07 '11 at 11:05
  • @Flukey fair point, but in this case it's shared hosting so it's out of the question – Pekka Dec 07 '11 at 11:25
  • @Pekka Ah yes indeed. shame :-( – Flukey Dec 07 '11 at 11:27
  • @Jean-Christophe Meillaud: Thanks. When I put above **.htaccess** in content folder than it successfully shows index page but when I click any link on index page, it shows following error: `Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Apache/2.2 Server at example.com Port 80` – Student Dec 07 '11 at 14:01
  • I added my current public folder .htaccess file content in my question above. do I need to change anything in this file? Thanks – Student Dec 07 '11 at 14:02
  • I have zend library folder outside public folder(in content folder). Will this .htaccess file effect each call to that library classes. – Student Dec 07 '11 at 14:12
1

put index.php file into the public folder and put .htaccess in the root folder, witch contents

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

Options -Indexes
Bart
  • 495
  • 1
  • 5
  • 16
1

it is straightforward , just move public directory contents to the parent so all files in /www.example.com/web/content/public become on /www.example.com/web/content

and don't forget to edit include path inside index.php file to work with the new location

Muhannad A.Alhariri
  • 3,702
  • 4
  • 30
  • 46