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视频教程
The above is the detailed content of apache pseudo-static general rules. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools
