最好的 PHP 搜索引擎友好方法
您可以推荐什么方法来创建搜索引擎友好的 URL?当用 PHP 编码时就是这样。理想情况下,我想要类似的东西:
http://www.example.com/article/523544
所以它不会显示它正在打开的文件(例如article.php)
What method can you recommended for creating search engine-friendly URLs? When coding in PHP that is. Ideally I would like something like:
http://www.example.com/article/523544
So it doesn't display the file it's opening (eg article.php)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
生成一个 SEO 友好的 URL 是非常有必要的,这样大多数搜索引擎都可以轻松地对其进行索引。最有趣的部分是,URL 可以轻松地与页面内容相关联,并且用户可以根据关键字生成漂亮的 URL他想在不同的搜索引擎(例如 google.com、google.co.in、bing.com)上对页面进行排名。
拥有漂亮链接的最佳示例是 Wordpress。它实际上将动态页面 URL 存储在数据库本身中。并且当 Pretty Ur 被调用时,内部会调用 htaccess 并重定向到系统中的原始动态页面。
It is quite necessary to generate a SEO friendly URL's so that most of the Search engines can easily index it.And the most interesting part with it that URL can easily correlate to the Page Content and the User can generate a Pretty URL as per the keywords he want to rank the page on different Search Engines(e.g. google.com,google.co.in,bing.com)
The best example to have Pretty Links is on Wordpress.It actually stores the Dynamic Page URL's in the Database itself.And when the Pretty Ur is being called,internally the htaccess is called and it redirects to the original dynamic page in the system.
的一些基本提示
可能会帮助您。
SO中的一些主题:
编辑:
您需要在文档根目录中放置一个
.htaccess
文件,其中包含以下规则:确保 Apache 中启用
mod_rewrite
并且您可以使用它。如果您阅读本主题中的一些问题,它将帮助您了解 mod_rewrite 的工作原理。
为了使您的网址对搜索引擎更友好,您可能需要使用“slugs”,因此您需要清理您的文章标题,如此网址中所示。
Some basic tips from
may help you.
Some topics in SO:
Edit:
You need to place a
.htaccess
file in your document root that includes the following rules:Make sure
mod_rewrite
enabled in Apache and you are allowed to use it.If you read some questions in SO in this topic it will help you understand how mod_rewrite works.
To make your urls more search engine friendly you may want to use 'slugs' so you need to sanitize your article titles like in this url.
理想情况下,您的 URL 需要包含有关 URL 主题的内容。您给出了 http://www.example.com/article/523544 的示例,其中这比使用标准查询字符串要好,但它仍然不理想,因为任何搜索引擎都可以从中看到它是一篇文章。
重要的是要记住,最接近域的段(段是每个斜杠之间的字符串)是最重要的:
http://www.example.com/most-important/next -important/less-important/
我个人总是尝试使用以下 URL 结构,并保持我的页面/文章标题的唯一性:
http://www.example.com/this-wonderful-article
请注意使用破折号而不是下划线,这通常被称为首选方法。使用这种方法,我通常会生成文章的 slug(“this-wonderful-article”)并将其保存在数据库中,然后搜索它而不是 ID。
意识到有时仅使用 slug 非常困难,尤其是对于较大的网站。您可能有多篇具有相同标题的文章,或者网站可能包含您无法控制的用户提交的内容。如果是这种情况,您可以放心使用该 ID,但请务必在 URL 中包含文章的标题。例如: http://www.example.com/this-wonderful-article/29587< /a>
如果您正在寻找使用这些 URL 的方法,那么我建议您查看一些 mod_rewrite 教程。就我个人而言,我使用的框架可以为我完成大部分工作,例如 CodeIgniter (http://www.codeigniter.com< /a>),或者您可以使用 Zend Framework 或 CakePHP 之类的东西。如果您只写文章,那么可能值得考虑像 WordPress 这样强大的 CMS,尽管这很大程度上取决于您的要求。
Ideally your URL needs to contain something about the topic of the URL. You gave the example of http://www.example.com/article/523544, where this is better than using standard query strings, it's still not ideal, as all that any search engine can see from it is that it's an article.
It's important to remember that the segment (a segment is the string between each slash) closest to the domain is the most important:
http://www.example.com/most-important/next-important/less-important/
I personally always try to use the following URL structure, and keep my page/article titles unique:
http://www.example.com/this-wonderful-article
Notice the use of dashes and not underscores, this is generally known as the preferred method. Using this method I usually generate and save the article's slug ('this-wonderful-article') in the database, and then search for that instead of an ID.
Appreciated that sometimes it's very difficult to just use slug, especially with a larger website. You may have multiple articles with the same title, or the website may have user-submitted content over which you have no control. If this is the case, you can use the ID without any worries, but just be sure to include the title of the article in the URL. Eg: http://www.example.com/this-wonderful-article/29587
If you're looking for a method of using these URLs then I'd suggest looking at some mod_rewrite tutorials. Personally I use a framework that does the majority of the legwork for me such as CodeIgniter (http://www.codeigniter.com), or you could use something like the Zend Framework or CakePHP. If you're only doing articles then it might be worth looking into a sturdy CMS like WordPress, although this depends largely on your requirements.