我在 cakephp 中完成了一个简单的 cms,但注意到 url 看起来并不那么漂亮。至于显示任何页面 url 看起来像cakephp/pages/1。什么是让它看起来更好和对 SEO 友好的好方法?
3 回答
links:
cakephp/pages/page_title_here
cakephp/pages/another_example_page_title
controller:
class Pages extends CI_Controller {
public function index($page = false)
{
if($page && file_exists('./application/views/pages/'.$page.'.php')) { $this->load->view($page); } else { show_404(); }
}
}
this controller would search for a template name equivalent to what you typed, i.e. if you are trying to reach pages/aboutus it would load the template from application/views/pages/aboutus.php
route:
$route['pages/(:any)'] = 'pages/index/$1';
CakePHP 有很好的规则来提供对 SEO 友好的 URL,而无需修改任何基本代码。您所要做的就是将您的视图文件放入您的app/views/pages
文件夹中。
例如,如果您有 'home'、'about' 和 contact_us' 这样的页面,只需将 'home.ctp'、'about.ctp' 和 'contact_us.ctp' 放在 pages 文件夹中。
所以,文件夹结构应该是这样的:
/app/
/views/
/pages/
/home
/about
/contact_us
访问页面的 URL 结构应如下所示:
http://www.yourwebsite.com/pages/home
http://www.yourwebsite.com/pages/about
http://www.yourwebsite.com/pages/contact_us
我认为,使用 SEO 的扩展更容易解决。试试这个高级 SEO 套件http://mirasvit.com/magento-extensions/advanced-seo-suite.html