Zend Framework - do not treat /public/directory as a controller - zend-framework

Is it possible to request a directory over http in the Zend /public/ directory without it being treated as a controller?
Eg, I have a directory, /public/facebook/ that contains facebook app data but Zend is (as default expected behaviour) giving "facebook controller missing" error when I request http://mysite.com/facebook.

This is because the default RewriteRules provided with Zend are redirecting all requests to the Zend Framework Bootstrapper (index.php).
The best thing to do, IMHO, is to add an exception to this Rule. Then there's more than one way to do it. You could use RewriteCond (and for example avoid the general redirect for existing directory or files in /public). But you could maybe filter it in the RewriteRule expression as well. This is an example with exception in the RewritreRule, so withoutt RewriteCond:
RewriteRule !(public/facebook/(.*\.php))|(public/(.*\.pdf))|(externalauthent\.php)|(favicon.ico)|(images/(.*\.(ico|gif|jpg|png|bmp|JPG|JPEG|BMP|GIF|PNG)))|(css/(.*\.css))|(js/(.*\.*))$ /index.php [L]

If you have content in this url, ZF don't try to found facebook controller, You need add a folder named facebook, and a file index.php into this folder

This work for me:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/public_directory_name
RewriteRule ^.*$ index.php [NC,L]
Just replace 'public_directory_name' with the name of the directory you don't want Zend to treat as a controller.
Answered in a different worded question: htaccess - do not rewrite in this case

Related

Zend Framework Error : The requested URL was not found

I'm trying to set up my zend framework application on this host but I'm getting a Requested URL not found error:
The application isn't at the root level i.e its in a folder like: www.mysite.com/zendapp/public
The error says that it can't locate the index.php file even though the url given in the erro message is correct.
Is this an htaccess issue? The homepage opens fine - the issue arises when I click on any link. Here is my htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
URL rewrite is enabled on the host.
Two things to check:
RewriteBase in your .htaccess
baseUrl property of the front controller

Running Zend Framework in a subfolder - Problems with default controller

I am starting a Zend application and I need to put it in a sub folder like this:
/subfolder
application
public
...
I did the following:
I set the base url in application.ini:
resources.frontController.baseUrl = "/subfolder"
I moved the .htaccess from the public folder directly into /subfolder, while changing the htaccess as follows:
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]
That's all I did. And everything works as expected. I can add controller blog with action view and can access it by calling:
/subfolder/blog/view
the url view helper and stuff work right too. The only thing that does not work is the default controller. So when I enter:
/subolder/
I get 403 (forbidden). If I enter
/subfolder/index
...it works. What am I missing?!
Thanks in advance!
teebee
you do not need to make any change in your zf public folder, just create an .htaccess file into the "/subfolder" directory with the following lines
# Rewrite rules
RewriteEngine on
RewriteRule (.*) ./public/$1
Replace
RewriteRule ^.$ public/index.php [NC,L]
with
RewriteRule ^.$ http://addressto/index.php [R=302,NC]
or
RewriteRule ^.*$ /public/index.php [NC,L]
i'm not sure if putting ZF folders other than public into publicly accessible folder is right.It will impose your site on security flaws. You must put ZF'S public folder' contents into your server`s public folder and put other folders into a non-publicly accessible folder.If you need more that one instance of your ZF application you may use Zend module system.Please refer to zend online documentation for more details.

Zend application problem on iis6

When I'm passing the URL like http://localhost/home/index/index in my application I'm getting the module=>default, controller=>index, action=>index. Whatever may be the URL i'm getting the same thing. I'm running the application on IIS6 in windows 2003 platform. If i'm overriding the module as 'home' in Zend_Controller_Request_Abstract=>getModuleName() method then my home page is coming fine. I'm unable to get where exactly it is overriding the value to 'default','index','index'. Can any one help me?
Thanks in advance
Update:
The problem is with $_SERVER['HTTP_X_REWRITE_URL']. I'm getting the same URI into both $_SERVER['HTTP_X_REWRITE_URL'] and $_SERVER['REQUEST_URI'] like /public_mvc/index.php. I'm not overriding the value of $_SERVER['HTTP_X_REWRITE_URL'] anywhere in my code. My .htaccess code is like this.
RewriteEngine on
RewriteRule ^admin-mvc(.*)$ public_mvc/admin.php [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^[\w/\%](?:.(?!(?:js|ico|gif|jpg|png|css|html)$)[\w\%]$)? public_mvc/index.php [I]
RewriteRule ^$ /home [r=301,nc]
I'm using ISAPI Rewrite 3 for URL Rewriting.
this is how Zend Framework handles the "default" module.
You can access your root path like this:
domain.tld/
domain.tld/index
domain.tld/index/index
domain.tld/default/index/index
all request will result in
module: default
controller: index
action: index
Update 1:
Probably there is a static route for module home configured
http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.static
which sends requests for
/home/index/index
to
/default/index/index
Update 2:
Make sure you have Isapi_Rewrite installed as indicated here (search for IIS):
http://framework.zend.com/manual/en/zend.controller.router.html
Update 3:
Add this rewirte rule to your .htaccess (as indicated in Zend article of Update 2):
RewriteRule ^[\w/\%]*(?:\.(?!(?:js|ico|gif|jpg|png|css|html)$)[\w\%]*$)? /index.php [I]
Update 4:
Try the following code in your .htaccess (it is the recommendation from Zend article of Update 2)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule ^[\w/\%]*(?:\.(?!(?:js|ico|gif|jpg|png|css|html)$)[\w\%]*$)? /index.php [I]
If this does not work, I'm not sure what the solution is. I'm not using IIS and not familiar with the particularities there...

zend framework deployment in server

I have a server, where I have uploaded my work in zend framework(in a subdomain). the folder name is 'visit'.
So, When I go to: http://mysitename.com/visit, it shows a directory structure:
Parent Directory
application/
docs/
library/
nbproject/
public/
tests/
But when I go to: http://mysitename.com/visit/public, i get the index page of my project.
But I want to get my index page , when I type: http://mysitename.com/visit
can you please give me the correct htaccess it need?
Also, these other approaches to deploying in shared hosting can help:
Zend Framework on shared hosting
http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/
http://www.ttech.it/en/article/2010/03/zend-framework-all-projects-files-on-document-root/
In particular, an answer by tharkun led me to write it up in more detail in a blog post.
You can do this with the following rule set, which is in part a partially modified version of the one described in the documentation.
.htaccess file in /visit:
RewriteEngine on
# Guard against people visiting /public/ directly
RewriteCond %{THE_REQUEST} ^[A-Z]\s/visit/public/
RewriteRule ^public/(.*)$ /visit/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
# Make sure we've rewritten to the ./public/ directory already
RewriteCond $0 ^public/
RewriteRule ^.*$ - [NC,L]
# The index file is now at /visit/public/index.php
RewriteRule ^.*$ /visit/public/index.php [NC,L]

How to avoid index.php in Zend Framework?

I'm using the Zend Router and so things like (/ and /index.php) or (/about and /index.php/about) ends up as the same here.
However, /index.php/whatever should not exist as it is the exactly same resource as /whatever so it doesn't make a sense the duplication.
How do I avoid this?
Even http://zendframework.com/manual/en/zend.controller.router.html and http://zendframework.com/index.php/manual/en/zend.controller.router.html both exists. It doesn't make any sense at all...
1) Don't link to it (like the urls in your question) and let it be a hidden feature. It won't matter, basically.
or
2) Add a rewrite-rule to strip out /index.php from any request containing it. You have to be sure to forward it to index.php so that you still can handle it, and you probably want to send a status code beginning with 3.
Seems that your mod_rewrite is not configured properly (is mod_rewrite enabled in Apache? Is .htaccess configured properly?). When it would be, you wouldn't have to type index.php at all.
Edit:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^index.php [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]