📄 1252.html
字号:
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=296
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=76
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=100
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=98
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=79
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=103
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=26
border=0></TD>
<TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR>
<TR>
<TD colSpan=3><A title=linux知识宝库
href="index.html" tppabs="http://www.linuxhero.com/docs/index.html"><IMG height=83
src="images/header_r1_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c1.gif" width=472 border=0
name=header_r1_c1></A></TD>
<TD colSpan=3>
<form action="http://www.linuxhero.com/docs/search.html" method=get>
<table
style="BORDER-RIGHT: #c4c4c4 1px solid; BORDER-TOP: #c4c4c4 1px solid; BORDER-LEFT: #c4c4c4 1px solid; BORDER-BOTTOM: #c4c4c4 1px solid"
cellspacing=0 cellpadding=3 width="95%" border=0 align="center">
<tbody>
<tr>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif">
<div align=center><font class=normalfont>搜索文章:
<input type=hidden value=result name=action2>
<input type=radio checked value=title name=type>标题
<input type=radio value=content name=type>内容
<input type=image src="images/button_go.gif" tppabs="http://www.linuxhero.com/docs/images/button_go.gif" border=0 name=image2>
</font></div>
</td>
</tr>
<tr>
<td noWrap>
<div align="center">
<input maxlength=100 size=30 name=keyword2>
</div>
</td>
</tr></tbody>
</table>
</form>
</TD>
<TD rowSpan=2><IMG src="images/header_r1_c7.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c7.gif" width=26 border=0 name=header_r1_c7></TD>
<TD><IMG height=83 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 border=0></TD></TR>
<TR>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif"><IMG height=22
src="images/header_r2_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r2_c1.gif" width=296 border=0
name=header_r2_c1></TD>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
<DIV align=right><FONT class=normalfont>当前位置:
<A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
<font color="#FF6699">>></font>
<A href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</A> | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
</TD>
<TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff
border=0>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
<TR>
<TD vAlign=top align=middle width="60%">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
<TBODY>
<TR>
<TD vAlign=top width="80%">
<DIV align=center>
<FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
</FORM>
<TABLE cellSpacing=0 cellPadding=0 width="95%"
border=0><TBODY>
<TR>
<TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif"
height=30></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>Apache重写规则的常见应用</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:吴阿亭<br>来自:Linux知识宝库<br>联系方式:无名<br><br>---- 本文旨在提供如何用Apache重写规则来解决一些常见的URL重写方法的问题,通过常见的实例给用户一些使用重写规则的基本方法和线索。<br>
<br>
一、为什么需要用重写规则<br>
<br>
---- 网站的生命在于不断地进行更新和维护,根据业务发展的需求转移服务器进行维护、重新组织目录结构、变换URL甚至改变到新的域名等情况是经常发生的。为了让客户不会因此受到任何影响,最好的方法就是使用Apache Rewrite Rule(重写规则)。<br>
<br>
二、重写规则的作用范围<br>
<br>
---- 1.使用在Apache主配置文件httpd.conf中。<br>
---- 2.使用在httpd.conf里定义的虚拟主机配置中。<br>
---- 3.使用在基本目录的跨越配置文件.htaccess中。<br>
<br>
三、重写规则的应用条件<br>
<br>
---- 当用户的Web请求最终被导向到某台Web服务器的Apache守护进程,Apache根据配置文件判断该请求是主配置还是虚拟主机,再根据用户在浏览器中请求的URL来匹配重写规则,并且根据实际的请求路径匹配.htaccess中的重写规则,最后把请求的内容传回给用户。该响应可能有2种。<br>
<br>
---- 1.将请求内容外部重定向(Redirect)到另一个URL<br>
---- 让浏览器再次以新的URL发出请求(R=301或者R=302,临时的或是永久的重定向)。<br>
<br>
---- 例如,一个网站有正规的URL和别名URL,对别名URL进行重定向到正规URL,或者网站改换成了新的域名,则把旧的域名重定向到新的域名。<br>
<br>
---- 2.由Apache内部子请求代理产生新的内容送回给客户[P,L]<br>
---- 这是Apache内部根据重写后的URL,通过代理模块请求内容并将最终内容送回给客户,客户端浏览器不必再次请求,浏览器中的URL不会被重写,但实际内容由Apache根据重写规则后的URL生成。<br>
<br>
---- 例如,在公司防火墙上运行的Apache启动这种代理重写规则,代理对内部网段上的Web服务器的请求。<br>
<br>
四、重写规则怎样工作<br>
<br>
---- 我们假定在编译Apache时已经把mod_rewrite编译成模块,确信您的httpd.conf中有LoadModule rewrite_module libexec/mod_rewrite.so,并且在Addmodule中有Addmodule mod_rewrite.c,则可以使用重写规则。<br>
<br>
---- 当外部请求到达Apache,Apache调用重写规则中的定义来重写由用户浏览器指定请求的URL,最后被重写的URL如果是重定向,则送交浏览器做再一次请求;如果是代理则把重写后的URL交给代理模块请求最终的内容(Content),最后把内容送回给浏览器。<br>
<br>
五、何时使用.htaccess中的重写规则定义<br>
<br>
---- 假如您对网站内容所在的服务器没有管理员权限,或者您的网站内容放在ISP的服务器上托管,无法改写主配置文件,但是您对Web站点内容所在的目录有写权限,则可以设置自己的.htaccess文件达到同样的目的。但您需要确定主配置文件中对您的网站所在的目录定义了下面的内容,否则您的.htaccess不会工作。<br>
<br>
---- < Directory /usr/local/apache/htdocs/www.abc.com> options indexes followsymLinks<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -