ZendFramework: Forcing Zend to point to root of the domain?

HI

Currently my web application opens when I point the domain to http://example.com/public/

will it be possible to make the web application to work if i point to http://example.com/

Here is the contents of the .htaccess file under the public folder:


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]


Any help is appreciated.

Thanks

Yes, that should be possible if you move that .htaccess to the root directory change index.php to public/index.php


SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]

btw, that code is a bit weird. If you negate all the RewriteConds at the start, you only need one rule instead of two. You also then don’t need the [OR]s anymore.


SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ public/index.php [NC,L]

Also, since you don’t need to match the whole URL because you want to send everything to public/index.php, you can (and should) replace .* with .?


SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? public/index.php [NC,L]

Hi

Thanks for the reply

After moving the .htaccess file to the myblog folder, i get this error

Message: Invalid controller specified (myblog)

The URL I am using is

http://localhost/myblog/index/show

Where:

myblog = folder name where I have the project
index = controller
show = action

If you want to run the code in “myblog”, why not rename “public” to “myblog” ?
Also, if you want to run the code in “myblog”, why would you ask how you can run it in the root of your domain ?

Hi

if I rename “public” to “myblog”, my site will run as example[dot]com/myblog, which is what I dont want. I want to run as http://example[dot]com

So what I will do is upload all the contents of “myblog” to example[dot]com

so the structure of example.com will be

example[dot]com
–application
----controllers
----views
----models
–docs
–library
–public
–tests

Hope that answers your questions.

Thanks :slight_smile:

Can’t you upload it such that you have

–application
----controllers
----views
----models
–docs
–library
–example[dot]com <– document root
–tests

some host allow for it and it’s a much better structure than the one you’re proposing IMHO.
Mostly because this completely prevents access to any directory other than “public” without having to explicitly forbid it like you would using your structure.

Cannot do that since I am on a shared hosting and my document root will be example[dot]com. so if I follow your suggestion then my url will be

example[dot]com/example[dot]com

No you’d better not do that :slight_smile:

So, is your question now answered? I’m a bit confused (and I haven’t had my :coffee: yet today)

No Sir

My question is still unanswered.

I want my site to run as example[dot]com/controller/action but currently its running as example[dot]com/public/controller/action

Please help

Can you put the index.php in the root of the web space instead of in the public/? You’d probably need to rewrite the index.php to change a few paths, but that should not be too hard.

It could probably be get to work with this public/ dir, but putting index.php in the root directory would be a lot easier.