I was explaining to our SEO specialist that cakephp url structure is domain/controller/view/params
so to view a particular product the URL might be something like this:
example.com/products/show/product-name-slug
This would then map to the show function on the products controller with the product-name-slug as a parameter so it could render the correct product page.
He thought this was good but asked if I could name the controller p and the view d so the url would then be:
example.com/p/d/product-name-slug
Since this would make the appropriate keywords (product-name-slug) have a higher ratio over the entire url.
I understand where he is coming from, from a SEO perspective but this make no sense from a programming perspective giving controllers and views single letter names.
Does the ambiguous controller/view names in the URL make that much of a difference? If so, what would be a good compromising solution?
having additional route in configuration:
example.com/seo/product-name-slug would make code and SEO person happy
Router::connect(
'/seo/:slug',
array('controller' => 'products', 'action' => 'show'),
array(
'pass' => array('slug')
)
);
It makes a big difference what is in your URL. I never ever used the default URL structure of CakePHP. It is good to have it by default, but it would make an unacceptable constraint.
Cake wouldn't be worthy to be called a framework if it couldn't map actions to arbitrary URLs http://book.cakephp.org/2.0/en/development/routing.html#route-elements
You can even match regexp to actions:
Router::connect(
'/:controller/:year/:month/:day',
array('action' => 'index', 'day' => null),
array(
'year' => '[12][0-9]{3}',
'month' => '0[1-9]|1[012]',
'day' => '0[1-9]|[12][0-9]|3[01]'
)
);
Related
We are converting an exisiting HTML site into a CMS using CakePHP. Since SEO of the site has been mapped with keywords and indexed by Google the static pages i want to have urls to have the extention .html
I had a look at the Document here
But am not quite sure how to achieve this in the right way.
Any one who has worked on it can give some pointers?
simply put this line into your Router Router::parseExtensions('html');
This will tell the Router to cut off the .html as an Extension and parse what remains.
To Create correct Links to the Pages you have to give the Link() function another Parameter called "ext".
Like this:
$this->Html->link(
'Super Seo link',
array(
'controller' => 'anyController',
'action' => 'someAction',
'title' => 'seo-title-for-gods-sake',
'ext' => 'html'
) );
Have fun! Florian
i'm having troubles with my routes.php file, in the past my applcation works fine with the routes like this:
Router::connect( '/imprenta_online/:family/:subfamily/:id/:title/:quantity_id/:description/:days/*',
array('controller' => 'imprenta_online', 'action' => 'home'),
array('pass' => array('slug','slug', 'id','slug', 'slug', 'quantity_id', 'slug', 'slug')
));
but now, the SEO manager needs to remove the controller from the url, i'm trying to do it in the routes.php and, first, this change works for THIS URLS, but all the routes that uses the prefix backend (backend_index, backend_edit...) show me errors on paginate...
I'm not "good" whit this, so i'd like to know what can i do???
I need some help to know which changes i need to do, all the others routes works by default with cake routes, so i didn't have to changes them.
I'm using CakePHP to one of my project. When I was designing the URL, I know CakePHP does well when I use
$this->Html->Link('Add Post', array('controller'=>'posts', 'action'=>'edit', 1234))
CakePHP will generate URI /appname/posts/edit/1234. But what I'm thinking /appname/post/1234/edit is better than the former one. I couldn't find a solution to workaround with it.
I've tried
$this->Html->Link('Add Post', array('controller'=>'posts', 1234, 'action'=>'edit'))
but CakePHP will ignore the order of array.
Does anyone know how to achieve this URL? Basically I don't want to modify function Router::url, what I need is to write code in my ctp view file and CakePHP to know the right order I put. How can I do that?
BTW, I'm using CakePHP 2.3.
This is a job for routing, more specifically reverse routing : http://book.cakephp.org/2.0/en/development/routing.html
In app/Config/routes.php you could add something along the lines of the following:
Router::connect(
'/:controller/:id/:action',
array('controller' => 'posts', 'action' => 'edit'),
array('id' => '[0-9]+')
);
Here, you tell Cake to reverse route any request coming from the edit method of the posts controller by defining the order of pre-route named parameters. In your view, the link should be constructed like this:
echo $this->Html->link('Add Post', array(
'controller' => 'posts',
'action' => 'edit',
'id' => 1234
));
Note the extra id parameter being passed that we assigned in routes.php. The Url should look like:
http://appdomain.com/posts/1234/edit
In my humble opinion, this is considered bad practice both from a conventional and SEO standpoint.
Is it possible to store mixed html and php content in a db table and have it rendered in views? If I have the following in the table
<?php echo $html->link('Cool product 1', array('controller' => 'products', 'action' => 'view', 1), array('target' => '_blank')); ?>
this is what get's rendered:
link('Cool product 1', array('controller' => 'products', 'action' => 'view', 1), array('target' => '_blank')); ?>
I'd like the link , not the code. How can I achieve that?
UPDATE
It's for a multi-lingual site. I'd like to store the different static pages, in different languages, in a table, instead of having them in the page view folder.
I'd like to keep my helper code, so that I can create and test my pages locally before putting them online, and not having to worry about urls.
I'd like to put them in a table as it would simplify my code. I could link them to my site hierarchy, that is in a table.
Either store the link as HTML in your database or you could try using Eval to run the code.
Update: To get around the problem with the opening PHP tag you can try using eval like this: eval('?>' . $content);
But I think it's a bad idea to store plan PHP code into your database. Maybe explaining what you would like to achieve and why you are using this approach would help getting better answers.
Someone said "if eval is the answer, the question was wrong". You should consider to rethink what you are trying to achieve.
I've a new question :)
I'll briefly explain what I'm trying to achieve. Right now I have an url that looks like this.
/products/index/brand:figleaves
I want this to look like this
/brand/figleaves
By writing the following route rule I get what I want.
Router::connect('/brand/:brand/*', array('controller' => 'products', 'action' => 'index'));
Everything goes fine, but then I discovered the pagination logic has been destructed.
If I click on 'next page' I get redirected to the url /products/index/page:2.
it doesn't pass the brand parameter
it redirects back to the products_controller and not to the url I defined in the route rule.
In fact I'd need this as url /brand/figleaves/page:2.
Strange thing is if I browse to /products/index/brand:figleaves and click on Next, then I get redirected to /brand/figleaves/page:2. How can this be explained?
I'd appreciate some help with this :)
Kind Regards,
Laurent
For those interested in how I solved this.
I just defined some options in the paginator in my view and passed the value explicitly, like this.
$this->Paginator->options(array
('url'=> array(
'controller' => 'products',
'action' => 'index',
'brand'=>$this->params['brand']
)));
That does the job :)