pretty网址&安培;搜索引擎友好的网址? [英] Pretty URL & SEO-friendly URL?

查看:227
本文介绍了pretty网址&安培;搜索引擎友好的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以做简单的事情,像

I can do simple things like

RewriteRule ^/news$ /page/news.php [L]
RewriteRule ^/news/(.*)$ /page/news.php?id=$1 [L]

但如果我要发2个参数是这样什么

but what if I want to send 2 parameters like this

http://www.example.com/link/param1/param1_value/参数2 / param2_value

最后,我想也知道实现搜索引擎友好的URL像计算器

Lastly, I want to also know implementing SEO friendly URL like stackoverflow

虽然我可以访问与网址的网页像

though I can get access to a page with URL like

http://www.example.com/doc_no/

刚装修的URL以

http://www.example.com/doc_no/this-is-在-文章

给我一些建议与例子片断。

Give me some suggestion with example snippets.

推荐答案

我知道PHP symfony框架可以让你做到这一点。

I know that the PHP symfony framework allows you to do that.

它是如何工作:
在Apache配置,使用mod_rewrite将所有收到的resquest重定向到一个单一入口点(在symfony这就是所谓的前端控制器)

How does it work : In apache config, use mod_rewrite to redirect ALL incoming resquest to a single entry point (in symfony this is called the "front controller")

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

在此前端控制器你要创建一个请求对象,它保存URL提供的所有信息。

In this front controller you are going to create a "Request" object which holds all the informations provided by the URL.

例如,你可以说后的第一件事了/是PHP文件的名字来称呼和其他一切都是参数值,以便:
http://example.com/file/id/2 将调用file.php使用id = 2

For example you could say that the first thing after the "/" is the name of the PHP file to call and everything else are parameters and values so that : http://example.com/file/id/2 will call file.php with id=2

要做到这一点,只需使用一些章exp和设计你请求课堂上认真。对于上面的请求类中的例子应该同时提供getRequestedAction()和的getParameter(字符串参数)的方法。当请求对象,以调用正确的文件/动作/法完全填充将要使用的getRequestedAction()方法。

To do that, just use some reg exp and design you "Request" class carefully. For the example above the "Request" class should provide both getRequestedAction() and getParameter(string parameter) methods. The getRequestedAction() method will be used when the "Request" object is fully populated in order to call the correct file/action/method.

如果你选择填充的URL章都EXP和_GET数组的解析请求对象的参数数组,你可能会得到的地步:
http://example.com/file/id/2 是相同的 http://example.com/file?id=2
(而且两者可以同时工作)

if you choose to populate the parameter array of the request object with both reg exp on the URL and a parsing of the _GET array, you may get to the point where : http://example.com/file/id/2 is the same as http://example.com/file?id=2 (and both can work)

您可以选择忽略扩展(http://example.com/file.html相同的http:// example.com/file ),还是不行。

you can choose to ignore extensions (http://example.com/file.html is the same as http://example.com/file), or not.

最后,对于一些网址,你可以选择忽略最后一个'/'之后去一切。因此: http://example.com/question/3/where-is-khadafi < /一>是相同的 http://example.com/question/ 3 / IS-Linux的好于窗户

Finally, for some URL, you can choose to just ignore everything that goes after the last '/'. So that : http://example.com/question/3/where-is-khadafi is the same as http://example.com/question/3/is-linux-better-than-windows

在不同的file.php,只需用$请求 - >的getParameter('身份证')来获得,而不是使用_GET或_POST阵列的ID参数的值。

In the different file.php, just use $request->getParameter('id') to get the value of the "id" parameter, instead of using the _GET or _POST arrays.

整点是


  1. 重定向所有传入的通信,以一个单一的前端控制器

  2. 在该文件中,创建一个包含运行站点所需的所有信息请求对象

  3. 呼叫基于包含在该请求对象的信息正确的动作(PHP文件)

  4. 的行动里面,用这个请求对象来获取包含在URL中的参数

希望这有助于

这篇关于pretty网址&安培;搜索引擎友好的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆