[经验]
godaddy上win主机配置php的伪静态
|
|
在godaddy的win主机上安装了个php程序,想做下伪静态,结果发现添加.net的web.config重写规则就可以实现php的伪静态。
很简单,编写个web.config,上传到win主机空间的根目录下。
我的web.config如下:- <?xml version="1.0" encoding="UTF-8"?>
- <configuration>
- <system.webServer>
- <rewrite>
- <rules>
- <rule name="indexre">
- <match url="^index.html$" />
- <action type="Rewrite" url="/index.php" />
- </rule>
- <rule name="listcategory">
- <match url="^listcategory.html$" />
- <action type="Rewrite" url="/listcategory.php" />
- </rule>
- <rule name="listnew">
- <match url="^listnew.html$" />
- <action type="Rewrite" url="/listnew.php" />
- </rule>
- <rule name="showcategory">
- <match url="^category/(\d+?).html$" />
- <action type="Rewrite" url="/showcategory.php\?id={R:1}" />
- </rule>
- <rule name="listsoft">
- <match url="^list/(\d+?).html$" />
- <action type="Rewrite" url="/listsoft.php\?id={R:1}" />
- </rule>
- <rule name="listsoft page">
- <match url="^list/(\d+?)-(\d+?).html$" />
- <action type="Rewrite" url="/listsoft.php\?id={R:1}&p={R:2}" />
- </rule>
- <rule name="showsoft">
- <match url="^show/(\d+?).html$" />
- <action type="Rewrite" url="/showsoft.php\?id={R:1}" />
- </rule>
- <rule name="softdown">
- <match url="^down/(\d+?)-(\d+?).html$" />
- <action type="Rewrite" url="/softdown.php\?sid={R:1}&id={R:2}" />
- </rule>
- </rules>
- </rewrite>
-
- </system.webServer>
- <system.web>
- <customErrors mode="Off" />
- <globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8" />
- </system.web>
- </configuration>
复制代码 详细的看Rule的规则那部分把。
我的godaddy演示:
www.souduu.com |
评分
-
查看全部评分
|
|
|
|
|
|
|
|
|
|
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
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
chenxi
发表于 2010-2-4 19:58:08
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
133ad
发表于 2010-2-4 21:27:32
|
显示全部楼层
|
|
|
|
|
|
|
|