apche如何使用rewrite实现伪静态

<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]-->

<!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->

1.       配置 apache, 启用 rewrite 机制

httpd.conf 中启用 rewrite

LoadModule rewrite_module modules/mod_rewrite.so

2.       配置虚拟主机

c hosts 文件添加你的 ip 和 域名对应

127.0.0.1       www.hsp.com

http.conf 文件中启用虚拟主机

# Virtual hosts 启用虚拟主机

Include conf/extra/httpd-vhosts.conf

 

3. 配置 httpd_vhosts.conf 文件

 

 

 

 

<Direcotry > 段的配置,默认值,是在 httpd.conf 的中配置,看根目录 .

 

 

<VirtualHost *:80>

    #ServerAdmin webmaster@dummy-host2.somenet.com

    # 文档的根目录

    DocumentRoot "C:/myenv/apache/htdocs/static3"

    # 域名

    ServerName www.hsp.com

    ErrorLog "logs/dummy-host2.somenet.com-error.log"

    #CustomLog "logs/dummy-host2.somenet.com-access.log" common

    # 配置 rewrite 相关选项 ,

    <Directory "C:/myenv/apache/htdocs/static3">

    # 拒绝所有的访问

    #Deny from all

    Allow from all

    # 是否显示列表 ( 在发布项目后一般是不启用 , 对于这个配置,针对 DocumentRoothtdos 外的目录生效 )

    #Options +indexes

    # 是否启用 rewrite

    #Allowoverride  all

    </Directory>

</VirtualHost>

4. 在目录下添加了一个 .htaccess  文件,这个文件时配置 rewrite 机制和规则

 

<IfModule rewrite_module>

# 写你的 rewrite 规则

RewriteEngine On

#news-id(\d+)\.html$ 是规则   news.php?id=$1 是转发的页面

# 正则 子表达式 捕获 反向引用

#  "news-id33.html"

# 可以配置多个规则,匹配的顺序是从上到下

RewriteRule  news-id(\d+)\.html$   news.php?id=$1

RewriteRule  news-id(\d+)\.html$     error.php

</IfModule>

 

 

综合使用案例

 

 

 

1.       这个 rewrite 的规则也直接在 < Direcotry > 段直接配置

 

 

<Directory "C:/myenv/apache/htdocs/static3">

    # 拒绝所有的访问

    #Deny from all

     Allow from all

    # 是否显示列表 ( 在发布项目后一般是不启用 , 对于这个配置,针对 DocumentRoothtdos 外的目录生效 )

    #Options +indexes

    # 是否启用 rewrite

    Allowoverride  all

    # 我们有时候,也可以把 rewrite 机制和规则写这里

    #RewriteEngine On

    #RewriteRule  news-id(\d+)\.html$   news.php?id=$1

    </Directory>

 

 

使用伪静态来完成简单的新闻查询 .

☞ 伪静态是站在 seo 角度看 ., 他对于的页面不是存在的,而是每次查询数据库得到的信息 ,

真静态的页面是真的存在 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值