Zend Framework has problems with CamelCase Controller Names? - zend-framework

I have a Zend Framework application I've been working on my local machine, I've deploying it to a server but having .htaccess issues because some but not all routes fail with a "Page Not Found". Very weird that I can't access some controllers.
My .htaccess is:
RewriteBase /~user/path/to/app/public/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
This error does not occur on the local machine, only on the server. The only thing I can see that is common to the controllers that have a "Page Not Found" error on the server is that the Controller names are camel case.
Controllers that work: CustomerController, InvoiceController, StockController. Controllers that fail: SuppliersStockController, StockTypesController.
If I try to do something like 'www.route/to/app/stock-types/' or '/stock.types/' I get an "Application Error".

You are seeing the effect of a case sensitive file system.
When you go to /stocktypes/index, ZF will look for StocktypesController.php and succeed on case insensitive systems like Mac OS X and Windows. On Linux however, it will fail.
If you go to /stock-types/index, then ZF will look for StockTypesController.php and will find it on Linux.
If ZF finds a CamelCased controller name, then it will look for a view folder with a hyphen.

Related

Weird redirection behaviour on Apache2 server?

I've built a new site for our company, whom I recently started working for, and deployed it on a separate subdomain (http://site.mysite.com) to not interfere with some URLs that need to remain on the old subdomain.
The old HTML site (http://www.mysite.co/site) was, for some weird reason, placed inside the public/ folder of a Zend application, as public/site. We want to redirect this site, which used to be available on http://mysite.com/site folder, to our new site at http://site.mysite.com
I've edited the existing .htaccess file, inside the Zend public folder so it looks like such:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,NC,L]
# These four lines are my only alterations to this file...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(apps|site).* [NC]
RewriteRule .* http://site.mysite.com/ [R=301,L]**
RewriteRule ^cart/selectaddress$ https://%{SERVER_NAME}/cart/selectaddress [R,L]
Redirect 301 /photobook-sa http://www.mysite.com/photobooksa/
Redirect 301 /photobook-SA http://www.mysite.com/photobooksa/
Redirect 301 /photobookSA http://www.mysite.com/photobooksa/
RewriteRule ^channel\.html channel\.php
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
php_value session.auto_start 0
RewriteRule ^.*$ index.php [NC,L]
Header append P3P "CP=\"HONK IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA\""
AddDefaultCharset UTF-8
The idea is to trap http://mysite.com/apps/, http://mysite.com/apps/whatever and http://mysite.com/site/ and redirect these all, unconditionally to http://site.mysite.com
The problem is, the redirection only works for /apps and apps/whatever, not for /site. So I discovered the public/site folder, which strangely hosts the company site as a HTML only site, within a Zend project folder structure.
Problem is, when I delete this folder, the whole mysite.com and www.mysite.com domain fails, but for example mysite.com/apps still manages to redirect to site.mysite.com
So I tried editing public/site/index.php to look as follows:
<?php
header('Location: http://site.mysite.com'); exit;
and it works, but only for a few requests, then I get a server error.
I also tried adding a .htaccess inside public/site/.htaccess with the following:
Redirect 301 http://site.mysite.com
which also, works initially, but then fails with a server error after a few requests?
I have no idea what's up, no clue as to why the virtual host is dependant on the public/site folder to work, which not even mentioned in the virtual host setups.
I grepped all the controllers in the Zend application/controllers folder to try and see if I can find anything that remotely mentions this /site folder, but no matches found.
I'm pulling the hair out of my scalp with this strange behaviour, can someone please help?
Also last point, this is an Amason AWS server, which I'm not entirely familiar with, could it be that this server has something funny going on, that's non-standard in terms of Apache configuration, DNS setup or something mysteriously automagic?
We've not been able to resolve this issue, and unable to figure out why our methods work only for a few minutes. I'm suspecting something weird happening with Amazon AWS.
The only way we could fix, was by adding an index.html inside the culprit /site folder, using a small JavaScript snippet to redirect the site from the client side.

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

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

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

Subdomain and Zend Framework

I have an Zend Framework application with a subdomain that works well in my local development environment. Now I'm trying to put it on the live location, in a shared hosting environment. I have made the subdomain in DirectAdmin.
This is the default content of the .htaccess in public_html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I have removed the folder public_html/subdomain because I want that everything goes through index.php. But the problem is that if I go to subdomain.example.com I get a 500 Internal Server Error. How can I solve this?
This sounds like a host-specific issue. Typically, if you were running your own Apache server, you would create a VirtualHost directive that would point your subdomain to your application's public folder.
I know some hosts will treat each domain / subdomain as it's separate folder. If your host is expecting you to have a public_html/subdomain folder, why not try making the subdomain folder a symbolic link to your application's public folder?
ln -s /path/to/zf/public/folder /path/to/public_html/subdomain/folder