sorry, my English so bad.
In CakePHP 2.x, I want to redirect old link to new link in my website. But i got some issue.
Example:
mywebsite.com/news/news redirect to mywebsite.com/news
I use:
Router::redirect ('/news/news',
array('controller' => 'categories',
'action' => 'index',
'slug' => 'news'
),
array(
'status' => '301'
)
);
Router::connect('/news', array(
'controller' => 'categories',
'action' => 'index',
'slug' => 'news'
));
=> OK, it work.
But
Example:
mywebsite.com/news/news/a-b-c redirect to mywebsite.com/news/a-b-c
I use:
Router::redirect('/news/news/:slug',
array(
'controller' => 'articles',
'action' => 'view',
'category' => 'news'
),
array(
'status' => '301'
)
);
Router::connect('/news/:slug',
array(
'controller' => 'articles',
'action' => 'view',
'category' => 'news'
)
);
=> result is: mywebsite.com/articles/view/category:news
Please help, thank you !
You are redirecting all requests from news/news/* to articles/view/category:*
Do you need the 301 redirect in there at all?
Router::connect('/news/news/:slug',
array(
'controller' => 'news',
'action' => 'slug'
)
);
But on this basis, the controller will expect a defined action for every type of a-b-c action that can be passed as a slug
Related
My current url is
baseUrl/categories/category/categoryName/subcatName...
To convert this url into
baseUrl/categoryName/subcatName...
i am using following route
Router::connect(
'/:slug/*',
array(
'controller' => 'Categories',
'action' => 'category'
),
array(
'pass' => array('slug'),
'slug'=>'[a-zA-Z]+'
)
);
but it is creating problem with urls like:
baseUrl/home
baseUrl/myaccount ..
etc.
and redirect them to category action.
The common solution to this problem is to add a single letter (like Reddit).
baseUrl/r/slug/something-awesome
That way, you can make the route:
Router::connect(
'/r/:slug/*',
array(
'controller' => 'Categories',
'action' => 'category'
),
array(
'pass' => array('slug'),
'slug'=>'[a-zA-Z]+'
)
);
I know that these three routes can be condensed to a single route where :year and :month are optional parameters, but everything I've tried so far simply redirects me to the index if the exact parameters aren't given. For instance, "www.domain.com/blog/archive/" matches the first rules, but "www.domain.com/blog/archive/2013" was falling through to the index rule until I added another specific rule to match it.
Router::connect("/$slug/archive", array(
'plugin' => 'blog',
'controller' => 'blog_posts',
'action' => 'archive'
)
);
Router::connect("/$slug/archive/:year", array(
'plugin' => 'blog',
'controller' => 'blog_posts',
'action' => 'archive'
),
array('pass' => array('year') )
);
Router::connect("/$slug/archive/:year/:month", array(
'plugin' => 'blog',
'controller' => 'blog_posts',
'action' => 'archive'
),
array('pass' => array('year', 'month') )
);
Router::connect("/$slug/*", array(
'plugin' => 'blog',
'controller' => 'blog_posts',
'action' => 'index'
));
To make a single routing rule use the following code that matches "archive", "archive/2013" and "archive/2013/02"
Router::connect("/$slug/archive/*", array(
'plugin' => 'blog',
'controller' => 'blog_posts',
'action' => 'archive'
)
);
I can't figure out how I can write this right to get 'cat' and 'city' as $this->params['named'] within my controller:
Router::connect('/this-is-a-simple-url', array('controller' => 'listings', 'action' => 'search', 'cat' => 200, 'city' => 57));
I tried to place Router::connectNamed(array('cat', 'city')); before that rule, but this is not changing anything.
Please help me out!
Thanks so much!
you mean like:
Router::connect('/this-is-a-simple-url',
array(
'controller' => 'listings',
'action' => 'search',
array(
'named' => array(
'cat' => '[a-Z]+',
'city' => '[\d]+'
)
)
)
);
Using CakePHP 1.3 I am trying to get routers with language, slug, pagination, order .
Currently I have these:
Router::connect('/', array('controller' => 'pages', 'action' => 'index'));
Router::connect("/:controller/:slug", array('action' => 'view'), array('pass' => array('slug')));
Router::connect("/:lang", array('controller' => 'pages', 'action' => 'index'), array('lang' => 'fr|en|de'));
Router::connect("/:lang/:controller/:slug", array('action' => 'view'), array('lang' => 'fr|en|de', 'pass' => array('slug')));
and those are working with language and slug set or slug and pagination , but all three of them fails:
OK - /pages/view/page-slug/page:2
OK - /fr/pages/page-slug
FAIL - /pages/view/page-slug/page:2/lang:fr
I have tried
<?php $this->Paginator->options(array('url' => $this->passedArgs)); ?>
before the paginator but still the same result
Just try this code
Router::connectNamed(array('language','pagination','order','slug'));
Router::connect('/lang/pagination/:slug:order', array(
'plugin' => false,
'controller' => 'pages',
'action' => 'index',
),array(
"pass"=>array("lang","pagination","slug","order")
),array(
'pagination' => '[0-9]+',
'order' => '[0-9]+',
)
);
In my CakePHP App I'd like to pass arguments in a custom route.
What works now
(domain/controller/action/param)
domain.com/dealers/view/1
What I'd like to do
(domain/param/controller/action/param)
domain.com/washington/dealers/view/1
This is my code in routes.php:
Router::connect('/:city/dealers/view/:id', array('controller' => 'dealers', 'action' => 'view'),
array(
'pass' => array('city', 'id')
),
array('city' => '[a-z]+')
);
This just redirects domain.com/washington/dealers/view/1 to domain.com/dealers/index for the obvious reason that I did not properly pass the parameters. Does anyone know what I am missing?
city should not be in a separate array ex:
Router::connect(
'/:city/dealers/view/:id',
array('controller' => 'dealers', 'action' => 'index'),
array(
'pass' => array('city', 'id'),
'city' => '[a-z]+'
));