using seo user friendly in php

 ̄綄美尐妖づ 提交于 2019-11-27 15:53:23

Check out the mod_rewrite module, and maybe for a good starting point, this tutorial on how to take advantage of it with PHP.

You need to ensure two things:

  1. your application prints out the new URLs properly, and
  2. your webserver can understand that new URLs and rewrites them to your internal scheme or redirects them back to your application and your application does the rest.

The first part can be simply accomplished by using

echo '<a href="/index/page-1/title-articles"> … </a>';

instead of

echo '<a href="/index.php?page=1&title=articles"> … </a>';

The second part can be accomplished either with URl mapping features of your webserver (most webservers have a module like Apache’s mod_rewrite). With mod_rewrite, the following will do the rewrite:

RewriteEngine on
RewriteRule ^index/([^/-]+)-([^/]+)(.*) /index$3?$1=$2 [N,QSA]
RewriteRule ^index$ index.php [L]

The first rule will extract one parameter at a time and append it to the query. The second rule will finally rewrite the remaining /index URL path to /index.php.

I want to get the URL path as

/index/page-1/title-articles

Why? I’ve got two objections:

  1. index is a no-information and I doubt that it belongs in the URI
  2. page-1, as well as title-articles looks plain weird. Like with index, you should ask yourself whether this information belongs here. If it does, make clear that it’s the key of a key-value pair. Or remove it entirely.

Thus, I propose either:

/‹article›/1

or

/‹article›/page/1

or

/‹article›/page=1

or

/‹article›[1]

or

/articles/‹article›/page/1

Or any combination thereof. (In the above, ‹article› is a placeholder for the real title, the other words are literals).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!