apache伪静态划定规矩
1、简朴的重定向划定规矩
RewriteEngine On //启动划定规矩 RewriteBase / //根目录启动伪静态 RewriteRule ^index/$ index.php //接见index/ 那末就是接见index.php RewriteRule ^register/$ /s_youka/register.html //接见register 就是接见/s_youka/register.html
2、轻微庞杂的划定规矩
RewriteEngine on RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$1&id=$2 //背面的 $1 $2 对应前面的()内的代码 其他的是正则划定规矩 //^代表开首$代表完毕 [0-9]+ 是多个0到9之间的数字 \是转义背面的.
3、精准的划定规矩
/type.php?typeid=* –> /type*.html /type.php?typeid=*&page=* –> /type*page*.html RewriteRule ^/type([0-9]+).html$ /type.php?typeid=$1 [PT] RewriteRule ^/type([0-9]+)page([0-9]+).html$ /type.php?typeid=$1&page=$2 [PT] //重点引见下PT 交给下一条处置惩罚
1) R[=code](force redirect) 强迫外部重定向。强迫在替换字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.假如code不指定,将用缺省的302 HTTP状况码。
2) F(force URL to be forbidden)禁用URL,返回403HTTP状况码。
3) G(force URL to be gone) 强迫URL为GONE,返回410HTTP状况码。
4) P(force proxy) 强迫运用代办转发。
5) L(last rule) 表明当前划定规矩是末了一条划定规矩,住手剖析今后划定规矩的重写。
6) N(next round) 从新从第一条划定规矩最先运转重写历程。
7) C(chained with next rule) 与下一条划定规矩关联。假如划定规矩婚配则一般处置惩罚,该标志无效,假如不婚配,那末下面一切关联的划定规矩都跳过。
8) T=MIME-type(force MIME type) 强迫MIME范例
9) NS (used only if no internal sub-request) 只用于不是内部子要求
10) NC(no case) 不辨别大小写
11) QSA(query string append) 追加要求字符串
12) NE(no URI escaping of output) 不在输出转义特别字符
比方:RewriteRule /foo/(.*) /bar?arg=P1%3d$1 [R,NE] 将能准确的将/foo/zoo转换成/bar?arg=P1=zoo
13) PT(pass through to next handler) 传递给下一个处置惩罚
比方:
RewriteRule ^/abc(.*) /def$1 [PT] # 将会交给/def划定规矩处置惩罚 Alias /def /ghi
14) S=num(skip next rule(s)) 跳过num条划定规矩
15) E=VAR:VAL(set environment variable) 设置环境变量
4、discuz3x的划定规矩
RewriteEngine On //开启 RewriteBase / //当前根目录 RewriteCond %{QUERY_STRING} ^(.*)$ //定义了划定规矩见效的前提-查询字符串 RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1 //topic-开首 .htm后缀 现实上市接见了 背面的地点
5、nginx相似
Nginx下设置伪静态要领与Apache差不多,直接在nginx.conf (或许在对应的*.conf) 中找到需设置伪静态划定规矩的效劳器对应字段,在server{ location/{ } }中增加以下代码:
server { listen 80 default_server; server_name _; location / { root /usr/share/nginx/html; index index.html index.htm; rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$2&id=$3; } }
增加后重启Nginx效劳即可见效!
引荐教程:PHP视频教程
以上就是apache伪静态通用划定规矩的细致内容,更多请关注ki4网别的相干文章!