美元初级url重写指南 - apache 2.2 中文版参考手册(Primary URL Rewrite Guide - Apache 2.2 Chinese version reference manual)

rewrite  时间:2021-01-20  阅读:()

初级url重写指南- apache 2.2中文版参考手册Primary URLRewrite Guide -Apache 2. 2 Chinese version reference manual Note: according to your server configuration, it may benecessary to make some small changes, for example here, toincrease the [PT] mark in additional to enable mod_alias andmod_userdir, or in order to adapt to the directory level(.Htaccess) configuration for the server level rules arerewritten. A specific rule set should be thoroughly understoodbefore considering the application so that the problem can beavoided.

Normalized URL

Description:

On some web servers, a resource will have multiple URL. Inpractice and publishing, the standard URL should be used, whileothers are abbreviated or only used internally. No matter whatform of URL users use in the request, they should eventuallysee the standard URL.

Solution

Perform an external HTTP redirection to all non-standard URLto change its display and subsequent request in the browseraddress bar. The rule set in the following example replaces the/~user with the standard /u/user, and modifies the suffixslashes omitted by /u/user.

Rewr iteRul e ^/~ ( [^/]+) /?/ (. *) u/$1/$2 [R]Rewri teRule ^/u/

( [^/]+) $/$1/$2 / [R]

Normalized host name

Description:

The purpose of this rule is to force the use of a specific hostname instead of other names. For example, if you want to forcethe use of www.example.com instead of example.com, you canmodify it on the basis of the following solution:

Solution

Sites running on non 80 ports

Rewr iteCond%{HTTP_HOST} ! ^ful ly\.qual if ied\.domain\.name[NC]Rewrit eCond%{HTTP_HOST} ! ^$Rewri teCond%{SERVER_PORT} !^80$Rewrit eRule ^/ (. *)http://ful ly.qual if ied.domai n.name:%{SERVER_PORT}/$1 [L, R]Sites running on 80 ports

Rewr iteCond%{HTTP_HOST} ! ^ful ly\.qual if ied\.domain\.name[NC]RewriteCond%{HTTP_HOST} ! ^$Rewri teRule ^/ (. *)http://ful ly.qualif ied.domain.name/$1[L, R]

Mobile DocumentRoot

Description:

Typically, the DocumentRoot of the web server corresponds

directly to URL "/", but it is often not at the highest level.For example, you want visitors to enter the /about/ directoryfirst when they enter the site. You can use the rule set givenbelow.

Solution

Just redirect "/" to "/about/":

Rewr iteEngine onRewriteRule /about/ ^/$[R]

You can also use the RedirectMatch directive to solve theproblem:

RedirectMatch http://example.com/e/www/ ^/$

Ending slash

Description:

Each network has a bitter end to slash problem referencedirectory, if omitted, the server will produce an error,because if the request is "/~quux/foo" instead of"/~quux/foo/",the server will find a file called foo, and it is a directory,so wrong. In general, you can use this FAQ entry approach tosolve problems. But sometimes rewriting rules are needed tosolve problems, for example, after applying many complexrewriting rules.

Solution

The solution to this delicate problem is to automatically addsuffix slashes to the server. In order to achieve the goal, anexternal redirection must be used to enable the browser toprocess subsequent requests correctly, such as requests forpictures. If you execute only one internal rewrite, it may bevalid only for the directory page, but not for the page witha relative URL, because the browser has the possibility ofrequesting embedded objects. For example, if there is noexternal redirection, the request for image.gif in the/~quux/foo/index.html page becomes a request to the

/~quux/image.gif! So, it should be written like this:rewriteengine onrewritebase / ~ quux / RewriteRule ^ foo$ foo/ [ R ]

又懒又疯狂的做法是把这些写入其宿主目录中的顶级.htaccess中rewriteengine onrewritebase / ~ quux / Rewri teCond % { } - Drequest_filename RewriteRule ^ 。 + 【^ / ]  1美元/ [ R ]但是这样一来会增加处理上的开销。

将用户主目录移动到不同Web服务器

描述

通常许多网管在建立一个新的Web服务器时都会有这样的要求重定向一个Web服务器上的所有用户主目录到另一个Web服务器。解决方案

很简单在老的Web服务器上重定向所有的” / ~用户/ anypath”到” HTTP / / / ~New Server用户/ anypath” rewriteengine onrewriterule ^ /~ + HTTP ///~New Server1美元[ R ]

在多个目录中搜索页面

描述

有时会有必要使Web服务器在多个目录中搜索页面对此下或者其他技术无能为力。

解决方案

编制一个明确的规则集以搜索目录中的文件

RewriteEngine on #首先尝试在目录中寻找找到即停RewriteCond/你/ docroot /目录/ % { request_fi lename } - frewriterule ^

+ /你/ docroot /目录/ 1美元[1] #然后尝试在DIR2中寻找找到即停RewriteCond/你/docroot/DIR2/% {request_filename}- frewriterule ^ + /你/ docroot / DIR2 / 1美元[1] #再找不到就继续寻找其他的别名或不同目录RewriteRule ^ + - [葡]按照URL的片段设置环境变量

描述

希望保持请求之间的状态信息又不希望使用CGI来包装所有页面只是通过分离URL中的有用信息来做到。

解决方案

可以用一个规则集来分离出状态信息并设置环境变量以备此后用于x s s i或CGI。这样一个” /富/ S = j av a /酒吧/”的URL会被解析为” /食品/酒吧/” 而环境变量状态则被设置为“j av a” 。rewriteengine onrewriterule ^ * / S =  [ ^ / ] + / * 1美元/ 3美元[ E =现状 2美元]

虚拟用户主机

描述

如果需要为用户用户名支持一个WWW.用户名。host.domai n.com的主页但不在此机器上建虚拟主机而是仅用在此机器上增加一个DNS记录的方法实现。

解决方案

仅能对包含”主持人 “头的HTTP / 1. 1请求实现。可以使用以下规则集内部地将http://www.username.hos t.com/anypath重写为/家/用户名/ anypathrewriteengine onrewritecond% { http_host } ^WWW\。 [ ^ ] +。主持人。 COM RewriteRule ^ + % { } 1美元http_host [C]R ewr i t e Ru l e ^ WWW \。 + + \\主机* /家庭/ 1美元2美元为外来访问者重定向用户主目录

描述

对不是来自本地域ourdoma i n. com的外来访问者的请求重定向其用户主目录URL到另一个Web服务器www. s omewh ere.com有时这种做法也会用在虚拟主机的配置段中。

解决方案

只须一个重写条件rewriteengine onrewri tecond%{remote_host }  ^ 。 +。 ourdomain\。 COM Rewrit eRule ^ / ~。 + HTTP / /www. somewhere。 COM /1美元[ R ]

重定向锚

描述

By default, redirected to aHTML anchor is not feasible, because'#' will be transferred to '%23' . This, in turn, breaks theredirection.

Solution

Using the [NE] flag in the RewriteRule instruction (notescaped) .

Time dependent rewriting

Description:

In the page content needs to change according to the time ofthe occasion, such as redirection of specific pages, etc. , many

network management still uses CGI script method, how to usemod_rewrite to achieve it?

Solution

There are many variables called TIME_xxx that can be used inrewriting conditions, and the combination of dictionary based"<STRING", "=STRING" and ">STRING" can be used to implementtime dependent rewriting:

Rewr iteEng ineonRewri teCond%{TIME_HOUR}%{TIME_MIN} >0700Rewrit eCond%{TIME_HOUR}%{TIME_MIN} <1900Rewri teRule

^foo\.html$foo.day.htmlRewriteRule

^foo\.html$foo.night.html

In this case the foo.html at 07:00-19:00 time point tofoo.day.html, and in the rest of the time to foo.night.html,the home page is a good function. . .

Forward compatibility of YYYY to XXXX

Description:

How to maintain the forward compatibility of URL (still virtual)after changing a large number of document.YYYY files todocument.XXXX (e.g. , .Html to.Phtml)?

Solution

Just rewrite the file according to the reference file and test

whether the file with the new extension exists or if it exists,use the new one, otherwise it will still be used.

# document.html will be rewritten as document.phtml backwardscompatible set of rules#if and only if document.phtml has timeand there is no document.html RewriteEngine onRewriteBase/~quux/# shear and remember basenameRewriteRule ^ (. *)\.html$$1 [C E=WasHTML:yes]#, if there is then rewritten asdocument.phtmlRewri teCond%{REQUEST_FILENAME} .phtml ^

-fRewriteRule (. *) $$1.phtml or [S=1]# to return to theprevious basenameRewri teCond%{ENV:WasHTML} ^

^yes$RewriteRule (. *) $$1.html

Content processing

From old to new (internal)

Description:

Assuming that the file foo.html has been renamed to bar.html,you need to be backward compatible with the old URL, that is,the user can still use the old URL, and feel that the file hasbeen renamed.

Solution

Rewrite the old URL into a new one internally through thefollowing rules:

Rewr iteEngine onRewriteBase /~quux/Rewr iteRul e ^ foo

\.html$bar.Html

恒创新客(317元)香港云服务器 2M带宽 三网CN2线路直连

恒创科技也有暑期的活动,其中香港服务器也有一定折扣,当然是针对新用户的,如果我们还没有注册过或者可以有办法注册到新用户的,可以买他们家的香港服务器活动价格,2M带宽香港云服务器317元。对于一般用途还是够用的。 活动链接:恒创暑期活动爆款活动均是针对新用户的。1、云服务器仅限首次购买恒创科技产品的新用户。1 核 1G 实例规格,单个账户限购 1台;其他活动机型,单个账户限购 3 台(必须在一个订单...

SugarHosts糖果主机六折 云服务器五折

也有在上个月介绍到糖果主机商12周年的促销活动,我有看到不少的朋友还是选择他们家的香港虚拟主机和美国虚拟主机比较多,同时有一个网友有联系到推荐入门的个人网站主机,最后建议他选择糖果主机的迷你主机方案,适合单个站点的。这次商家又推出所谓的秋季活动促销,这里一并整理看看这个服务商在秋季活动中有哪些值得选择的主机方案,比如虚拟主机最低可以享受六折,云服务器可以享受五折优惠。 官网地址:糖果主机秋季活动促...

HostYun全场9折,韩国VPS月付13.5元起,日本东京IIJ线路月付22.5元起

HostYun是一家成立于2008年的VPS主机品牌,原主机分享组织(hostshare.cn),商家以提供低端廉价VPS产品而广为人知,是小成本投入学习练手首选,主要提供基于XEN和KVM架构VPS主机,数据中心包括中国香港、日本、德国、韩国和美国的多个地区,大部分机房为国内直连或者CN2等优质线路。本月商家全场9折优惠码仍然有效,以KVM架构产品为例,优惠后韩国VPS月付13.5元起,日本东京...

rewrite为你推荐
手机内存卡数据恢复软件免费下载内存卡数据修复工具,有没有apk安卓版的骁龙750g和765g哪个好骁龙730G和骁龙835、联发科Helio G90T哪个更好?苹果x和xr哪个好苹果x,苹果xs,苹果xr,苹果xs max哪个更值得买?莫代尔和纯棉哪个好纯棉含莫代尔和100%莫代尔哪个好网校哪个好会计网校哪个好海克斯皮肤哪个好诺手二周年皮肤好不好,和海克斯那个比哪个好,二周年属于稀有吗qq空间登录QQ页面上空间不能登陆了,怎么回事?扣扣空间登录如何设置QQ空间快速登陆牡丹江教育云空间登录云端学习如何登录?360云盘网页版360云盘网页版分享的文件有何限制?
域名买卖 哈尔滨域名注册 vps论坛 免费申请域名 budgetvm 电影服务器 免费cdn加速 哈喽图床 天猫双十一秒杀 免费ddos防火墙 京东商城0元抢购 anylink 有益网络 空间出租 河南m值兑换 cn3 免费网页空间 美国独立日 海外空间 外贸空间 更多