以IIS10 下设置伪静态规则为例:
1、首先需要安装Url重写模块,百度搜索,下载完安装,URL Rewrite Module。
2、然后重启机器,可以在iis全局看到URL rewrite模块。
3、然后点击要设置伪静态规则的站点,双击“URL 重写”图标。
4、然后进入“URL 重写”界面,点击右侧的“导入规则”。
5、进入“导入 mod_rewrite”界面,点击配置文件下面框最后的三个点。
6、找到伪静态规则文件:.htaccess,选中并点击打开。
7、回到“导入 mod_rewrite”界面,点击“导入”规则。
8、最后,点击右栏的“应用”按钮。
9、至此伪静态配置完成,iis上的伪静态规则是写在web.confg,在网站根目录上web.confg已写上相关程序规则
利用.htaccess文件对PHP网站进行伪静态处理要考虑两点:一.服务器支持伪静态,比如Apache要开启mod_rewrite模块支持
二.利用.htaccess完成伪静态需要根据不同的网站系统进行不同的设置,以下是一些常见系统的.htaccess设定:
01.wordpress:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
02.Phpwind
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
RewriteRule ^(.*)simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2
03.Discuz
RewriteEngine On
# Rewrite 系统规则请勿修改
RewriteRule ^archiver/((fid|tid)-[0-9]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
RewriteRule ^tag-(.+)\.html$ tag.php?name=$1
04.ecshop
RewriteEngine On
# direct one-word access
RewriteRule ^index\.html$ index\.php [L]
RewriteRule ^category$ index\.php [L]
# access any object by its numeric identifier
RewriteRule ^feed-c([0-9]+)\.xml$ feed\.php\?cat=$1 [L]
RewriteRule ^feed-b([0-9]+)\.xml$ feed\.php\?brand=$1 [L]
RewriteRule ^feed\.xml$ feed\.php [L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2 [QSA,L]
RewriteRule ^category-([0-9]+)(.*)\.html$ category\.php\?id=$1 [QSA,L]
RewriteRule ^goods-([0-9]+)(.*)\.html$ goods\.php\?id=$1 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2&sort=$3&order=$4 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2 [QSA,L]
RewriteRule ^article_cat-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1 [QSA,L]
RewriteRule ^article-([0-9]+)(.*)\.html$ article\.php\?id=$1 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html brand\.php\?id=$1&cat=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2&page=$3 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2 [QSA,L]
RewriteRule ^brand-([0-9]+)(.*)\.html brand\.php\?id=$1 [QSA,L]
RewriteRule ^tag-(.*)\.html search\.php\?keywords=$1 [QSA,L]
RewriteRule ^snatch-([0-9]+)\.html$ snatch\.php\?id=$1 [QSA,L]
RewriteRule ^group_buy-([0-9]+)\.html$ group_buy\.php\?act=view&id=$1 [QSA,L]
RewriteRule ^auction-([0-9]+)\.html$ auction\.php\?act=view&id=$1 [QSA,L]
05.phpcms
RewriteEngine On
RewriteRule ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=
$3&page=$4
RewriteRule ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=
$3&page=$4
RewriteRule ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=lists&catid=$2&page=$3
Centos下让nginx支持.htaccess文件实现伪静态的方法在Google上搜索的资料很多人都说nginx目前不支持.htaccess文件,我按照nginx的规则试验了一下,结果发现nginx是完全支持.htaccess文件的!方法如下:1.
在需要使用.htaccess文件的目录下新建一个.htaccess文件,如我的一个Discuz论坛目录:vi
/var/www/html/bbs/.htaccess
www.dnjsb.com
2.
在里面输入规则,我这里输入Discuz的伪静态规则:#
nginx
rewrite
rulerewrite
^(.*)/archiver/((fid|tid)-[w-]+.html)$
$1/archiver/index.php?$2
lastrewrite
^(.*)/forum-([0-9]+)-([0-9]+).html$
$1/forumdisplay.php?fid=$2&page=$3
lastrewrite
^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$
$1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
lastrewrite
^(.*)/profile-(username|uid)-(.+).html$
$1/viewpro.php?$2=$3
lastrewrite
^(.*)/space-(username|uid)-(.+).html$
$1/space.php?$2=$3
lastrewrite
^(.*)/tag-(.+).html$
$1/tag.php?name=$2
last#
end
nginx
rewrite
rulewq保存退出。3.
修改nginx配置文件:
www.dnjsb.com
vi
/etc/nginx/nginx.conf4.
在需要添加伪静态的虚拟主机的server{}中引入.htaccess文件,include
/var/www/html/bbs/.htaccessinclude
/var/www/html/bbs/.htaccess(把这个改成你.htaccess文件的具体位置)wq保存退出。5.
重新加载nginx配置文件:/etc/init.d/nginx
reload重新打开网页看看,如果伪静态正常就证明你的rewrite
rule语法是正确的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)