分享

写回答

发帖

[经验] godaddy上win主机配置php的伪静态

GoDaddy GoDaddy 17551 人阅读 | 20 人回复

发表于 2010-2-3 15:07:47 | 显示全部楼层 |阅读模式

在godaddy的win主机上安装了个php程序,想做下伪静态,结果发现添加.net的web.config重写规则就可以实现php的伪静态。
很简单,编写个web.config,上传到win主机空间的根目录下。
我的web.config如下:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3.     <system.webServer>
  4.         <rewrite>
  5.             <rules>
  6.                             <rule name="indexre">
  7.                     <match url="^index.html$" />
  8.                     <action type="Rewrite" url="/index.php" />
  9.                 </rule>
  10.                                 <rule name="listcategory">
  11.                     <match url="^listcategory.html$" />
  12.                     <action type="Rewrite" url="/listcategory.php" />
  13.                 </rule>
  14.                                 <rule name="listnew">
  15.                     <match url="^listnew.html$" />
  16.                     <action type="Rewrite" url="/listnew.php" />
  17.                 </rule>
  18.                                 <rule name="showcategory">
  19.                     <match url="^category/(\d+?).html$" />
  20.                     <action type="Rewrite" url="/showcategory.php\?id={R:1}" />
  21.                 </rule>
  22.                 <rule name="listsoft">
  23.                     <match url="^list/(\d+?).html$" />
  24.                     <action type="Rewrite" url="/listsoft.php\?id={R:1}" />
  25.                 </rule>
  26.                                 <rule name="listsoft page">
  27.                     <match url="^list/(\d+?)-(\d+?).html$" />
  28.                     <action type="Rewrite" url="/listsoft.php\?id={R:1}&amp;p={R:2}" />
  29.                 </rule>
  30.                 <rule name="showsoft">
  31.                     <match url="^show/(\d+?).html$" />
  32.                     <action type="Rewrite" url="/showsoft.php\?id={R:1}" />
  33.                 </rule>
  34.                                 <rule name="softdown">
  35.                     <match url="^down/(\d+?)-(\d+?).html$" />
  36.                     <action type="Rewrite" url="/softdown.php\?sid={R:1}&amp;id={R:2}" />
  37.                 </rule>
  38.             </rules>
  39.         </rewrite>
  40.   
  41.   </system.webServer>
  42. <system.web>
  43. <customErrors mode="Off" />
  44. <globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8" />
  45. </system.web>
  46. </configuration>
复制代码
详细的看Rule的规则那部分把。
我的godaddy演示:
www.souduu.com

评分

参与人数 1威望 +1 金币 +5 银币 +5 收起 理由
add.c + 1 + 5 + 5 精品文章

查看全部评分

回答|共 20 个

add.c

发表于 2010-2-3 16:12:02 | 显示全部楼层

不过php的程序如果可能还是推荐使用linux的空间

呵呵笑站长

发表于 2010-2-4 15:28:46 | 显示全部楼层

留个记号

yerencao

发表于 2010-2-4 15:51:44 | 显示全部楼层

学习,弄论坛的时候可以用上,哈哈!

shinewater

发表于 2010-2-4 16:52:42 | 显示全部楼层

你这是重写到根目录,重写到子目录里的文件怎样写呢?

whys

发表于 2010-2-4 17:07:42 | 显示全部楼层

哇,楼主的空间速度好快

souduu

发表于 2010-2-4 19:06:01 | 显示全部楼层

原帖由 shinewater 于 2010-2-4 04:52 PM 发表
你这是重写到根目录,重写到子目录里的文件怎样写呢?


重写到子目录也一样呀!因为/代表根目录。
要重写到的地址只要以/开头,那就行。
例如a.html重写到根目录下list目录的b.php
那就是:

<rule name="r">
                    <match url="^a.html$" />
                    <action type="Rewrite" url="/list/b.php" />
                </rule>

只要牢记match是静态的地址,action是重写到的地址,/是根目录,就行呀。



而在match里,不用写根目录/符号,否则会出错。
例如:
http://www.souduu.com/show/2388.html
要重写到
http://www.souduu.com/phpshow/show.php?id=2388


match里不写根目录/

那就是:

<rule name="r">
                    <match url="^show/2388.html$" />
                    <action type="Rewrite" url="/phpshow/show.php?id=2388" />
                </rule>



为什么match里不写根目录/呢???

因为正则的写法,^代表开始,$代表结束,意思就是整句匹配。而^这个开始的意思就是从网站域名加/的后面部分开始的。

例如:

http://www.souduu.com/show/2388.html

http://www.souduu.com/phpshow/show.php?id=2388

^就表示从除去域名加/
http://www.souduu.com/后一位开始匹配,直到整个string结束,$代表结束标志。

也就是说:上面那个规则会将
http://www.souduu.com/show/2388.html
重写到
http://www.souduu.com/phpshow/show.php?id=2388

但不会将
http://www.souduu.com/softshow/2388.html
http://www.souduu.com/soft/show/2388.html
这样不以/根目录开始的冲写到
http://www.souduu.com/phpshow/show.php?id=2388

如果我想将
http://www.souduu.com/softshow/2388.html
http://www.souduu.com/soft/show/2388.html
重写到
http://www.souduu.com/phpshow/show.php?id=2388
怎么办呢?

嘿嘿,把^去掉,就行了。如:
<rule name="r">
                    <match url="show/2388.html$" />
                    <action type="Rewrite" url="/phpshow/show.php?id=2388" />
                </rule>

再扩展一下,想把
http://www.souduu.com/softshow/2388.html
http://www.souduu.com/soft/show/2388.html
http://www.souduu.com/softshow/2388.htmls
http://www.souduu.com/soft/show/2388.htmls
这样的也重写到
http://www.souduu.com/phpshow/show.php?id=2388

哈哈,把$也去掉,就行了。

表达能力差,可能高手看了会一笑而过,也不知道朋友你看明白了没有。

souduu

发表于 2010-2-4 19:09:21 | 显示全部楼层

原帖由 whys 于 2010-2-4 05:07 PM 发表
哇,楼主的空间速度好快


其实是我写的程序运行快。
另:你们的空间很慢吗?发来瞧瞧啊

[ 本帖最后由 souduu 于 2010-2-4 07:27 PM 编辑 ]

chenxi

发表于 2010-2-4 19:58:08 | 显示全部楼层

做一个记号,学习一下.

133ad

发表于 2010-2-4 21:27:32 | 显示全部楼层

收藏··
您需要登录后才可以回帖 登录 | 注册

本版积分规则