Yii URLFormat Path will not work - frameworks

For some reason, since I've enabled the urlManager, domain.com/site/logout/ or domain.com/logout/ will not work.
Here's my .htaccess:
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
... and here's my main.cfg
'components'=>array(
'assetManager' => array(
'linkAssets' => true,
),
'user'=>array(
'allowAutoLogin'=>true,
),
'request'=>array(
'baseUrl' => "http://google.com"
),
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'rules'=>array(
'post/<id:nd+>/<title:.*?>'=>'post/view',
'posts/<tag:.*?>'=>'post/index',
'<controller:nw+>/<action:nw+>'=>'<controller>/<action>',
),
),
Any ideas? Thanks :/

Related

TYPO3 realurl problems with subdomains and a global default domain

Normaly I've no problems configuring realurl. But this time I see no glue.
I've a configuration from old relurl 1.x, working with TYPO3 6.2. The goal is, to manage one global domain and some subdomains. The subdomains should work, but the global-domain should be the default domain for link-building.
root (1) [www.domain.tld]
..subpage1 (4) [subpage1.domain.tld]
....some pages (1004)
..subpage2 (5) [subpage2.domain.tld]
....some more pages (102)
explanation: name (PID) [domainrecord]
IE: "some more pages (102)" should be accessible with subpage2.domain.tld/some-more-pages but the links in menu should be www.domain.tld/subpage2/some-more-pages
A snippet of my realurl-conf:
$rootPids = array(
'www.domain.tld' => 1,
'subpage1.domain.tld' => 4,
'subpage2.domain.tld' => 5,
);
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT'] = array(
'init' => array(
'enableCHashCache' => 1,
'appendMissingSlash' => 'ifNotFile,redirect[301]',
'enableUrlDecodeCache' => 1,
'enableUrlEncodeCache' => 1,
'postVarSet_failureMode' => '',
),
'pagePath' => array(
'rootpage_id' => $rootPids[$_SERVER['HTTP_HOST']],
),
...
If I add domainrecords to subpage1 and subpage2, these domains will prepend all the time in links - thats not what I want.
And the part "subpage2" is removed from the default-url - which is also not what I want.
I figured out, that this is not a solution for realurl, it's a htaccess-thing.
I added the following lines to my htaccess and all is fine:
RewriteCond %{HTTP_HOST} subpage1.domain.tld$ [NC]
RewriteRule ^(.*)$ https://www.domain.tld/subpage1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} subpage2.domain.tld$ [NC]
RewriteRule ^(.*)$ https://www.domain.tld/subpage2/$1 [R=301,L]
And of course the other rootPids for subpage1 and subpage2 has to be removed from realurl-conf!
Cool.
Nested domain are not supported by RealUrl 2.x.
To make them work with RealUrl you must change your setup (eg. move pages or remove domains)

ZF1 Remove 'public/' from url

Using Zend_Navigation, i noticed that it's add '/public/' to all links.
How to remove this addition form url?
$navigation = array(
array(
'label' => 'Home',
'title' => 'Go Home',
'module' => 'default',
'controller' => 'index',
'action' => 'index',
'route' => 'default',
'order' => -100 // make sure home is the first page
),
array(
'label' => 'Test static page!',
'route' => 'pages',
'params' => array(
'permalink' => 'test'
)
)
);
$nav = new Zend_Navigation($navigation);
The solution was simple. Edit your bootsrap.ini like this:
resources.frontController.baseUrl = "/"
Simple way I'm using:
Put index.php to the root directory.
Define APPLICATION_PATH as following:
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
Run project without public part.
in your .htaccess file you need to add a rule for that,
try following,
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]
add these line in your .htaccess line, and see if it works..
or you can create a virtual host, which directly points to your public directory,
as folllowing,
<VirtualHost *>
ServerAdmin admin#localhost.com
DocumentRoot "C:/wamp/www/project/public"
ServerName localhost.test
ServerAlias localhost.test
<Directory "C:/wamp/www/project/public">
DirectoryIndex index.php
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
you need to follow somethings first in order to create a vhost.
OFFICIAL DOC FOR VIRTUAL HOST

User friendly urls revelsal

Lets say that I want to show http://example.com/topic/view/topicname/thenameofthetopic direclty as http://example.com/thenameofthetopic
So I have achieved that when entering http:// example.com/thenameofthetopic , it redirects you to the controller/action properly, and the website shows what I want to show, the problem is that of course, the URL changed, and I want it to maintain the format http://example.com/thenameofthetopic
Is that possible whitout touching the htaccess file? Just configuring it with yii
How should I do that?
Exactly your case is:
'components' => array(
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
"<name_of_topic:\w+>/" => 'controller/action'
),
),
)
You will get the name of topic in Yii::app()->request->getQuery('name_of_topic');
htaccess is Yii - classic, the must be present:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
I would advice you to do another way.
'components' => array(
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
"t/<name_of_topic:\w+>/" => 'controller/action'
),
),
)
So topic link will be http://www.example.com/t/name_of_topic.
This will allow you to use "a//" for articles etc.
One more thing. Read this article to find much interesting things http://www.yiiframework.com/doc/guide/1.1/en/topics.url

zend pagination url format

i've followed the pagination tutorial from http://framework.zend.com/manual/en/zend.paginator.usage.html
I have successfully implemented pagination for my site, but i am not satisfied with the URLs output for the paging. example url for page 2:
http://www.example.com/posts/index/page/2
What i would like is to remove the index and just have http://www.example.com/posts/page/2
Why is index included while accessing this->url(in the my_pagination_control.phtml from tutorial in link)?
Is there a way to gracefully just show posts/page/2? or even just posts/2?
I feel that the previous answer is not enough, I'll give mine. First of all you can add a router in your bootstrap.php that looks like:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initRoutes()
{
$Router = Zend_Controller_Front::getInstance()->getRouter();
$Route = new Zend_Controller_Router_Route(
':controller/*',
array(
'controller' => 'index',
'action' => 'index'
)
);
$Router->addRoute('paginator1', $Route);
$Route = new Zend_Controller_Router_Route(
':controller/:page/*',
array(
'controller' => 'index',
'action' => 'index',
),
array(
'page' => '[0-9]+'
)
);
$Router->addRoute('paginator2', $Route);
}
}
and then, use in your view this simple line:
echo $this->url(array('controller' => 'CONTROLLER-NAME', 'page' => 5), 'paginator1', TRUE);
echo $this->url(array('controller' => 'CONTROLLER-NAME', 'page' => 5), 'paginator2', TRUE);
In the case of 'paginator1', the url will be printed in this way:
/CONTROLLER-NAME/page/5
In the case of 'paginator2', the url will be printed in this way:
/CONTROLLER-NAME/5
Obviously where you see CONTROLLER-NAME will be the name of the controller you write.
You could do:
in your 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]
Link for reference: http://framework.zend.com/manual/en/zend.controller.router.html
Hope it helps

Zend custom Route not working if Index controller is not capitalized?

I'm testing a Zend project on my shared-hosting.I keep everything inside a folder 'Zend-project' not on the server public-root (cause I have there another project!).
this is the structure:
/public_root
/zend-project
/application
/configs
application.ini
/controllers
/layouts
/views
bootstrap.php
/css
/images
/javascript
/zend-library
.htaccess
index.php
I had to tweak a little the project cause I just can't change my document_root on a shared-hosting so I edited the .htaccess to this:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/favicon.ico$ [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /zend-project/index.php [NC,L]
but at the end everything seems to work fine except a single Url Route that I added to the router in my bootstrap.
edit:I tried creating a new controller 'TestController'..with a single action (called 'test')I tried to type the url with the controller lowercase (mysite.com/zend-project/test/test)and it's working!As I suspected there is something wrong with the 'index' word itself!cause any other controller works as a charme
this is bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initRoutes()
{
$frontController=Zend_Controller_Front::getInstance();
$router=$frontController->getRouter();
$router->removeDefaultRoutes();
$router->setGlobalParam('lang','en');
$router->addRoute(
'lang',
new Zend_Controller_Router_Route(':lang/:controller/:action',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
//the following route is not working remotely.
//Is working on local environment
$router->addRoute(
'langController',
new Zend_Controller_Router_Route(':controller/:action',
array(
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langIndex',
new Zend_Controller_Router_Route(':lang',
array('lang'=>':lang',
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
$router->addRoute(
'langNothing',
new Zend_Controller_Router_Route('',
array(
'module'=>'default',
'controller'=>'index',
'action'=>'index'
)
)
);
}
}
I tried to type the following urls (based on the custom routes I created)and everithing seems to work:
//this points to the pair controller/action -> index/index
mysite.com/zend-project/
//this points to the pair controller/action ->index/index in english lang
mysite.com/zend-project/en
//this points to the pair controller/action ->index/rooms in english lang
mysite.com/zend-project/en/index/rooms
But whenever I type:
mysite.com/zend-project/index/index
I receive the following message:
Not Found.The requested URL /zend-project/index/index was not found on this server.
It looks like the request doesn't reach the index.php file ..maybe an .htaccess problem??or what
thanks
edited
Found out that by typing the broken route's controller with capital letter it works :
//this works.Controller has capital letter
mysite.com/zend-project/Index/index
//this do not work.Controller has not capital letter
mysite.com/zend-project/index/index
why??
(by the way I'm on linux server..)
Remove this from httpd.conf
Options Includes ExecCGI MultiViews FollowSymLinks Indexes