我如何在PHP中进行URL重写?

编程入门 行业动态 更新时间:2024-10-26 14:41:06
本文介绍了我如何在PHP中进行URL重写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是一个双重问题:正确的答案将转到如何在PHP中执行,解释是否有任何优势,如果可能的话也会计数。

This is a double question: The correct answer will go to "How you do it in PHP" explaining if there is any advantage goes also counts if possible.

我只是好奇,因为我真的不知道,我在网页上看到很多。

I'm just curious because I really don't know and I see it a lot in webpages.

编辑:我不知道技术名称,但例如这里的Stackoverflow: stackoverflow/posts/edit/522452 就是我的意思是文件夹(这个术语以前在问题的标题中使用过)。

I don't know the technical name, but for example here on Stackoverflow: "stackoverflow/posts/edit/522452" is what I mean as "folders" (a term previously used in the title of the question).

推荐答案

如果您引用 / posts / edit / 522452 风格的网址,而不是 /posts.asp?action=edit&postid=522452 风格的网址(或不管它转换为后端),通常通过URL重写器来完成,比如 mod_rewrite的 。该URL的规则可能如下所示:

If you're referring to /posts/edit/522452-style URLs as opposed to /posts.asp?action=edit&postid=522452-style URLs (or whatever it translates to on the back end), this is typically done through a URL rewriter, such as mod_rewrite. A rule for that URL might look like this:

RewriteRule ^/posts/(\w+)/(\d+) /posts.asp?action=\1&postid=\2

两个主要优点这种类型的网址是:

The two primary advantages to this kind of URL are that:

  • 文件夹类型的网址对于人们来说更容易输入和记忆。 b $ b
  • 页面看起来像是HTTP代理的页面。传统上,代理不会使用参数缓存页面,因为它们不代表单独的内容并且频繁更改(认为搜索结果)。使用文件夹式URL可以正常缓存它们。
  • 在PHP中,您可以通过 $ _ GET ['action'] 和 $ _ GET ['postid'] ,就好像浏览器要求重写的表单一样。

    In PHP, you can then access these options via $_GET['action'] and $_GET['postid'], exactly as if the browser had asked for the rewritten form.

    更多推荐

    我如何在PHP中进行URL重写?

    本文发布于:2023-11-02 08:37:06,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1551914.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:重写   如何在   PHP   URL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!