using seo user friendly in php

末鹿安然 提交于 2019-12-17 14:25:51

问题


this is the URL path I currently use:

/index.php?page=1&title=articles

I want to get the URL path as

/index/page-1/title-articles

using SEO user friendly URLs in PHP.

And how to get the value of the "title"? Any one can help me pls.


回答1:


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




回答2:


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.




回答3:


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).



来源:https://stackoverflow.com/questions/1444151/using-seo-user-friendly-in-php

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