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
Related
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.
dynamic html redirects using routers
in the beginning I had no categories and all of my pages were root
example:
http://domain/somepage
This was great, but as my content over the years grew I need to categorize my content
so I added some routes see below
//routes.php
Router::connect(
"/:category/:slug",
array('controller' => 'controllername', 'action' => 'view'),
array(
'name'=>'[-A-Z0-9]+',
'pass' => array('category','slug')
)
);
//end
this works great and accomplished what I needed to do, but there is one problem the search engines .I need to write 301's for all of my links and I have over 8K pages.
The solution cakesphp's Router::redirect
The issue I am now having is I cant figurer out how to redirect my old links. I can for example redirect all of the links to one category, but that wont cut it. I need to redirect all of my links to the new location.
I am trying to use routes.php router :: redirect
if I do this my code it redirects to the category, but not the slug
Router::redirect(
'/:slug/*',
array(
'pass' => array('category/:slug'))
result
http://domain/category/
how can I get cake to redirect to
http://domain/category/slug ?
instead of http://domain/category/
I had all of my links pointing to the root directory
http://domain/somepage
http://domain/anotherpage
http://domain/ect
I needed to add categories
such as
`
http://domain.com/phones/samsung.php
http://domain.com/books/cakephp.php
`
I didn’t want to use .htaccees file because
My hosing provide limits me to 100 redirects
and i have over 8K links i need to redirect
I am trying to use cakes router ::redirect function in the routes.php file.
the below code works only for one category it doesn’t do it dynamically like I would like it too.
I tried to create a router class that would do this for me like you suggested, but to be honest with you I am not an expert in cakephp. Its easy to learn and a great framework I just dont know how to make my own classes or components yet. I just haven’t found good documentation to do this yet.
//routes.php
$move='category/'. stripslashes_deep ($_SERVER['REQUEST_URI']); Router::redirect('/:slug/*',$move, array('status' => 302)); code
Your best bet is to use a custom route class.
Custom routing extends the CakeRoute class and will allow you to return/add/modify parameters that are passed over.
CakePHP Custom Route Classes - How to Pass Arguments?
I want to access my sitemap.xml file in /mywebsite/sitemaps/xml/sitemap.xml
Reading some documentation, it is explained that I can reach the absolute URL by using:
Router::url('/',true)
For some reason it doesn't work. How to solve this?
If your site map xml is generated outside of CakePHP, then you can create the folders and file in /mywebsite/app/webroot/sitemaps/xml/sitemap.xml and avoid routing altogether.
If you are dynamically generating the xml through cake, then you don't want to hard-code the route. Rather, you would route to the controller and action that provide the xml return. A very basic example would be..
Router::connect(
'/sitemaps/xml/sitemap.xml',
array(
'controller' => 'Xml',
'action' => 'sitemap'
)
);
The XML documentation here can help you get started building and routing the site map.
http://book.cakephp.org/2.0/en/core-utility-libraries/xml.html
How do I make cakephp website URL SEO friendly? Is there a plugin available for cakephp 1.2.6
First define what you mean by "SEO friendly".
Most likely this just means you want to add the name of your "object" to the URL, i.e. add a slug. You can do that without any plugin:
echo $html->link($record['Model']['name'], array(
'controller' => 'foo',
'action' => 'bar',
$record['Model']['id'],
Inflector::slug($record['Model']['name'])
));
// -> /foo/bar/42/the-name
If you require any more customized URLs, first specify what exactly you need, then use Routing to create these custom URLs.
it's the only way to do it wothut any trouble...
but if you don't like id in the url, then you should take a title, remove all symbols, replace spaces with -, and write to the datebase...