PHP实现URL静态化

一种就是伪静态方式,即用户和搜索引擎看到的是.html后缀的静态页面,但实际上它还是动态程序,只不过是通过某种方式进行了伪装。

这种方式也有两种实现方式:第一种是通过web服务器,进行url rewrite实现链接的静态化,下面以apache为例来说明一下其实现方式。对于有服务器配置权限的用户,推荐使用apache的mod_rewrite模块,这里假设已经安装好mod_rewrite模块,打开apache的配置文件,找到相应主机的部分,添加以下代码:

  1. rewriteengine on 
  2. rewriterule ^/abc/([a-z]+)/([0-9]+).html$ /abc.php?action=$1&id=$2 

然后在shell里执行service httpd reload,让apache重新载入配置就好了,但对于我们大多数人来讲,我们购买的只是空间,根本没有权限去修改apache的配置文件,那就没有办法了吗?不,当然有办法,首先我们进入到我们的空间的根目录下(如public_html),然后建立一个文件名为.htaccess的文件。这个文件内容基本如下:

  1. rewriteengine on 
  2. rewritebase / 
  3. rewriterule ^post/([0-9]+).htm read.php?1 
  4. rewriterule ^post/([0-9]+)_([0-9]+).htm read.php?1&page=2 
  5. rewriterule ^post/([0-9]+)_([0-9]+)_([0-9]+).htm read.php?1&page=2&=3 

php程序写法

  1. function  mod_rewrite(){ 
  2.          if ( isset ( $_server [ ’ path_info ’ ])){ 
  3.                  $url   =   substr ( $_server [ ’ path_info ’ ] , 1 ); 
  4.                  $url   =   explode ( ’ / ’ , $url ); 
  5.                  foreach  ( $url   as   $key   => $value ){ 
  6.                          if ( $key % 2 != 1 ){ 
  7.                                  if ( $value != ’’ ) $_get [ $value ] = $url [ $key + 1 ]; 
  8.                                  $querystring [] = $value . ’ = ’ . $url [ $key + 1 ]; 
  9.                         } 
  10.                 } 
  11.                  $_server [ ’ query_string ’ ] = implode ( " & " , $querystring ); 
  12.     $_server [ ’ php_self ’ ] = substr ( $_server [ ’ php_self ’ ] 
  13.  , 0 , strpos ( $_server [ ’ php_self ’ ] , ’ .php ’ ) + 4 ); 
  14.                  $_server [ ’ request_uri ’ ] = $_server [ ’ php_self ’ ] 
  15. . ’ ? ’ . $_server [ ’ query_string ’ ]; 
  16.         } 
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » PHP实现URL静态化

205 评论

  1. buy avodart 0.5mg without prescription avodart 0.5mg sale buy ondansetron

  2. molnunat 200 mg generic cefdinir online buy lansoprazole for sale

  3. buy isotretinoin 20mg generic accutane 10mg cost prednisone 20mg generic

  4. purchase azithromycin for sale cost prednisolone buy neurontin 100mg

  5. buy generic cialis 40mg usa viagra overnight order viagra 100mg without prescription

  6. buy sumatriptan pills avodart 0.5mg uk order avodart 0.5mg sale

  7. buy tamsulosin 0.2mg pill flomax 0.4mg oral order spironolactone 25mg online

  8. biaxin 250mg for sale meclizine cost buy antivert 25 mg online

  9. indomethacin capsule flomax pills cost cenforce 50mg

  10. cost accutane 40mg acillin generic purchase ampicillin pill

  11. Nice article inspiring thanks. Hello Administ . onwin

  12. order avlosulfon 100mg without prescription buy tenormin 50mg buy cheap atenolol

  13. buy atorvastatin 20mg pills viagra 50mg cost sildenafil 100mg generic

  14. albuterol for sale online albuterol uk synthroid 150mcg us

  15. buy serophene for sale levitra tablet order plaquenil 400mg sale

  16. order synthroid 75mcg sale clomiphene uk purchase vardenafil pill

  17. methotrexate order online warfarin 5mg sale metoclopramide where to buy

  18. order sumatriptan 50mg avodart pills cost avodart 0.5mg

  19. simvastatin 10mg pills simvastatin sale order sildenafil 50mg for sale

  20. cialis mail order us cialis 5 mg viagra 50mg price

  21. is there a recall on amlodipine can i take asprin with norvasc started blood pre ssure med. norvasc but take cortef/florinef 2x day for adreanal insuf.

  22. how much seroquel seroquel. quetiapine overdose fatal

  23. buy ramipril 10mg generic cost amaryl order etoricoxib generic

  24. order metoprolol 50mg pill tenormin sale where can i buy medrol

  25. order rosuvastatin 10mg online cheap ezetimibe price oral motilium

  26. lamotrigine canada vermox pill minipress 2mg for sale

  27. buy azathioprine 50mg generic telmisartan usa telmisartan price

  28. buy cordarone no prescription buy coreg cheap dilantin sale

  29. order albendazole 400 mg generic aripiprazole usa medroxyprogesterone 5mg tablet

  30. ditropan 5mg ca ditropan 5mg pills how to get alendronate without a prescription

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡