我希望在我使用PHP开发的博客中,URL看起来像http://mysite.com/jan2006/best-day-of-my-life 而不是像http://mysite.com/viewblog.php?id=25这样的东西 “我生命中最美好的一天”是我博客文章的标题 我会用什么工具自动执行此操作? 这种技术有助于搜索引擎优化吗?
答案 0 :(得分:1)
您需要使用.htaccess和Apache的mod_rewrite。 Google和Google上有大量信息。 SO:
http://www.javascriptkit.com/howto/htaccess.shtml
http://www.besthostratings.com/articles/htaccess.html
http://www.bloghash.com/2006/11/beginners-guide-to-htaccess-file-with-examples/
但有一点需要注意的是,根据您所说的示例,您仍需要在您的URL中的特定博客帖子(即ID)中使用唯一标识符,例如:
类似于http://mysite.com/jan2006/best-day-of-my-life 这样的事情http://mysite.com/viewblog.php?id=25
实际上需要:
http://mysite.com/25/jan2006/best-day-of-my-life
或http://mysite.com/post/25/jan2006/best-day-of-my-life
如果您有Apache主机设置,则在您的根目录中需要一个名为“.htaccess”的文件。它的内容看起来像(例如):
# set up mod rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^post/(.*)/(.*)/(.*)$ viewblog.php?id=$1 [NC,L] # Handle requests for clean urls to blog posts
至于
这项技术是否有助于搜索引擎的最终化?
是的,是的,确实如此:
http://www.seocentro.com/articles/apache/mod_rewrite-seo-purposes.html
http://techie-buzz.com/how-to/create-seo-friendly-urls-using-mod-rewrite-and-php-part-1.html
http://www.seomoz.org/ugc/using-mod-rewrite-to-convert-dynamic-urls-to-seo-friendly-urls
http://webhostinggeeks.com/blog/2011/03/31/seo-friendly-links-with-mod_rewrite/
答案 1 :(得分:0)
从您的管理信息中心查看您的设置,应该有一个名为永久链接的部分。在这里,您可以改变永久链接的显示方式。