zoukankan      html  css  js  c++  java
  • URL重写

    URL重写

    https://en.wikipedia.org/wiki/Rewrite_engine

    A rewrite engine is a software component that performs rewriting on Uniform Resource Locators, modifying their appearance. This modification is called URL rewriting. It is a way of implementing URL mapping or routing within a web application. The engine is typically a component of a web server or web application framework. Rewritten URLs (sometimes known as short, pretty or fancy URLs, search engine friendly - SEF URLs, or slugs) are used to provide shorter and more relevant-looking links to web pages. The technique adds a layer of abstraction between the files used to generate a web page and the URL that is presented to the outside world.

    Web sites with dynamic content can use URLs that generate pages from the server using query string parameters. These are often rewritten to resemble URLs for static pages on a site with a subdirectory hierarchy. For example, the URL to a wiki page might be:

    http://example.com/w/index.php?title=Page_title
    

    but can be rewritten as:

    http://example.com/wiki/Page_title
    

    A blog might have a URL that encodes the dates of each entry:

    http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=19
    

    It can be altered like this:

    http://www.example.com/Blog/2006/12/19/
    

    Nginx重写

    https://xuexb.com/post/nginx-url-rewrite.html

    • server {
    • # 访问 /last.html 的时候,页面内容重写到 /index.html 中
    • rewrite /last.html /index.html last;
    •  
    • # 访问 /break.html 的时候,页面内容重写到 /index.html 中,并停止后续的匹配
    • rewrite /break.html /index.html break;
    •  
    • # 访问 /redirect.html 的时候,页面直接302定向到 /index.html中
    • rewrite /redirect.html /index.html redirect;
    •  
    • # 访问 /permanent.html 的时候,页面直接301定向到 /index.html中
    • rewrite /permanent.html /index.html permanent;
    •  
    • # 把 /html/*.html => /post/*.html ,301定向
    • rewrite ^/html/(.+?).html$ /post/$1.html permanent;
    •  
    • # 把 /search/key => /search.html?keyword=key
    • rewrite ^/search/([^/]+?)(/|$) /search.html?keyword=$1 permanent;
    • }
  • 相关阅读:
    03.通过商品课程初心商品信息
    04.支付宝支付流程
    02.创建商品(表)应用(App)
    01.商品模块表结构
    七牛云上传视频
    Django之序列化器
    Django之抽象基类
    权限系统
    python实现简单工厂模式
    01.git基本操作
  • 原文地址:https://www.cnblogs.com/lightsong/p/10122218.html
Copyright © 2011-2022 走看看