分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

URL重写

发布时间:2023-09-06 02:26责任编辑:胡小海关键词:暂无标签

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;
  • }

URL重写

原文地址:https://www.cnblogs.com/lightsong/p/10122218.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved