As far as I can see I've followed the Zend skeleton application tutorial to the letter (I actually went through it twice with the same result) but when I try to access zf2-tutorial.localhost/album I get the following error:
A 404 error occurred
Page not found.
The requested URL could not be matched by routing.
No Exception available
© 2005 - 2015 by Zend Technologies Ltd. All rights reserved.
Going to zf2-tutorial.localhost displays the Zend welcome page and the 404 is wrapped in the Zend styling so something at least appears to be working.
I have tried the offered solutions on similar questions here and here but to no avail, any ideas would be appreciated. Thanks.
Edit: I am using running the tutorial locally on XAMPP.
To get rid of problems connected with configuring server for working with zend i may recommend you installing WAMP server. Then by uploading zend files to subdirectory you will be able to start your turn with zend.
Try also using the below provided .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]
Seems this error not related to .htaccess, its configuration problem. Please ensure that you've defined needed rotes in Album\config\module.config.php file:
http://framework.zend.com/manual/current/en/user-guide/routing-and-controllers.html#routing-and-controllers
It turns out in module.config.php I had split the array with the controllers and router into two arrays by mistake. Combining them into one seems to have solved this particular issue.
Code follows:
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
),
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
);
Related
I deployed my php/Yii2 project (based on the basic template) to a shared hosting webspace. I want to access the project via an subdomain because an wordpress is running on the main domain. The normal controllers of the base project are working fine. The problem is that the framework can't find any controller that is in a module. The module itsef is registered properly.
The folder structure in the webspace is the following:
/
www
_wp (target folder of the main domain)
_project
web (target folder of the sub domain)
runtime
views
...
modules
testmodule
Module.php
views
models
controllers
The modules are configured like this:
'modules' => [
'testmodule' => [
'class' => 'app\modules\testmodule\Module',
],
],
The UrlManager is configured like this:
[
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'rules' => array(
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>'
),
];
The .htaccess file in the _project\web looks like this:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php? [L]
In the _project folder I do not have an .htaccess file.
On my local machine everything is working fine. On my webspace the controllers of the project itself are working fine. As soon as I navigate in a module i get an 404 Error of the yii framework. I debugged the project and found out that the module itself is loaded correctly. The problem is that the framework can not find the Controller Class because the function class_exists(controller) returns false. I don’t have an idea what i can do to fix this. Hopefully somesone here can help me, thanks a lot!
thanks to the comment of Michal Hynčica! I wrote my controllers lower case and yii2 is looking for them with CamelCase. This worked on windows. But on my shared hosting based on this did not work because of Case-sensivity!
I am trying to set-up Yii2 to use pretty URL.
In order to do so, I configured Yii2 and used the rewrite module of apache to make sure that we always enter by the entry point which is index.php
I made the following modification in the .htaccess file contained in the yii-application/frontend/web/ folder - folder that contains index.php (advanced yii2 template). For those modifications, I followed instructions found on various forums.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I have also made the following changes in the configuration of yii2 in order to activate pretty URL
$config = [
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
],
];
Note that Yii2 was working well before I made those changes.
Now if I try to connect using one of the following URL (like before modification), I see the landing page. The navigation will not work, I will always see the landing page.
http://localhost/frontend/
http://localhost/frontend/index.php
http://localhost/frontend/index.php?r=site/about-us
http://localhost/frontend/index.php?r=site/faq
If I try to connect using of the URLs below (as I should once pretty URL is configured properly), my brower displays an error message.
http://localhost/frontend/site/faq
http://localhost/frontend/site/account
http://localhost/frontend/site/index
Error message:
Not Found
The requested URL /web/yii-application/frontend/web/index.php was not found on this server.
Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80
However, it looks like the path is correct. The index.php file is actually in the folder C:\web\yii-application\frontend\web\index.php
How come my browser does not find the file?
Thanks for your help
From all your requests you are missing the web folder.
All your URLs should be
http://localhost/frontend/web/
http://localhost/frontend/web/index.php
http://localhost/frontend/web/index.php?r=site/about-us
http://localhost/frontend/web/index.php?r=site/faq
http://localhost/frontend/web/site/faq
http://localhost/frontend/web/site/account
http://localhost/frontend/web/site/index
Unless you set up a folder redirection but considering how you have things set up I seriously doubt that.
Well, PHP times.
My client wants me to use Yii2 as the framework for his project.
I got it up and running. No problem. I used the advanced template via composer.
Set my web root to /frontend/web, etc.
NOW, i want to use this url format
website.com/messages/ or website.com/messages/tom... etc.
Right now the way is setup shows website.com/index.php?r=messages/index...
I found this documentation...
https://github.com/yiisoft/yii2/blob/master/docs/guide/url.md
But i can't seem to get it straight.
Here are my steps...
I configured my apache server to point to /usr/www/payroll/frontend/web/
I added to my web folder a .htaccess file with this content.
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
I also added the component 'urlManager' as in the directions. It seems to catch the request and modify it.
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => 'false'
],
],
For example if I type website.com you can see it adds /site/index to the url. (without the url component active it simply adds /index.php?site/index)
So, obviously there's a modification perfomed to the url (via UrlManager) but I get 404 error
I am running out of ideas here. I am new to Php, Apache and Yii2. Any help, Greatly appreciated.
Thanks
To make pretty URL working on Yii 2.0 you need 2 things:
1: Edit /frontend/config/main.php (or the appropriate main config in your case) and add:
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
2: Add a .htaccess file in YOUR WEB ROOT folder.
In yii 2.0 advanced this is NOT project root directory but instead:
/frontend/web
.htaccess example:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
just change 'showScriptName' => 'false' to 'showScriptName' => false and it will work
Ok, here is the solution.
In recents version of Apache (from 2.3.9), AllowOverride is set to NONE by default. Previous versions have AllowOverride set to ALL.
Yii2 assumes that AllowOverride will be set to ALL.
If you want to read the whole thread at Yii Forum, here is the link
http://www.yiiframework.com/forum/index.php/topic/53295-url-manager-for-seo-friendly-url-404-error-code/
Thank you for your help and messages!
For Yii2 basic, I just added the codes below to /myappfolder/config/web.php:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName'=>false,
]
Also, added .htaccess in /myappfolder/web/ :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
This works well for me. Hope this helps others who have same problem. : )
If you want to use like this http://domain.com/controller_name/action_name , you only need to enable pretty url in your config file :
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => 'false'
],
],
Now you can use urls as you wish `website.com/messages/ or website.com/messages/tom.
If you want to use query string in your url this is how it works now in Yii 2 website.com/message?id=12
I've looked through the silex documentation http://silex.sensiolabs.org/doc/providers/security.html and I'm using HTTP Authentication to allow a single user into the backend of a system.
Although this works on the local copy, it doesn't on the server, refusing to login. I've had this issue before, when using a htpasswd file, and was able to fix this by running php in cgi mode, but that didn't help in this instance.
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'admin' => array(
'pattern' => '^/admin',
'http' => true,
'users' => array(
// raw password is foo
'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==') ,
),
),
)
));
There are some issues with the headers which contain the authorisation data in php-cgi on Apache. This could be your problem. Try adding a .htaccess file with the following:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Source : Symfony/Component/HttpFoundation/ServerBag.php
I am developing website with PHP Yii Framework and I am now stack, I need to start gii, but I can't do this. when i type www.example.com/index.php/gii or www.example.com/gii it gives me this error :
/gii/default/login // <- website redirects to here
This webpage has a redirect loop
The webpage at http://www.example.com/gii/default/login has resulted in too many redirects.
Clearing your cookies for this site or allowing third-party cookies may fix the problem.
If not, it is possibly a server configuration issue and not a problem with your computer.
I don't think that the error is because of modified htaccess and main configuration, but anyway here is main.php configuration file:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'site/page/<view:\w+>'=>'site/page',
'<controller:\w+>/<cact:\w+>/<action:\w+>'=>'<controller>/<cact>',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
and .htaccess :
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
#non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule ^.*$ /index.php [L]
So can you help me, please?
To use this path: index.php?r=gii/default/login , you must turn OFF the url manager in /protected/config/main.php
Also check urlManager's rules. That was the issue for me:
'components' => array(
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
// ...
// will handle `gii/default/login` uri and makes infinite redirection loop circle
'<controller:\w+>/<action:\w+>/<sub_action:\w+>'=>'<controller>/<action>',
// ...
),
),
),
Check if the gii module in your configuration file is there and it is uncommented.
If gii is not in there you should add it within the module array.
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>***choose a password***
),
),
More info for gii here
Like FelikZ mentioned, this might be because you have created a third param in a rule that uses \w+ instead of the default \d+ and hence will match "gii" as the controller, "default" as the action and "login" as the ID (or sub action, or whatever is mentioned).
My rules looked like the following:
'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
The fix is to add the following as the very first rule in order to make gii hit the right place:
'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',
Which should make your entire urlManager config look something like the following:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',
'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
This problem occurs because of the two sessions of the OP, for example cookie PHPSESSID there two domains domain .site.ru and admin.site.ru two different sessions. Delete PHPSESSID cookies and login to gii