Nginx detailed Rewrite pseudo-static rule steps
伪静态是一种可以把文件后缀改成任何可能的一种方法,如果我想把php文件伪静态成html文件,这种相当简单的,下面来介绍nginx 伪静态配置方法有需要了解的朋友可参考。
nginx里使用伪静态是直接在nginx.conf 中写规则的,并不需要像apache要开启写模块(mod_rewrite)才能进行伪静态。
nginx只需要打开nginx.conf配置文件,在server里面写需要的规则即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
然后重启nginx服务器伪静态就生效了,这种维护起来很是不方便我们可以把它写在外部文件如bbs_nginx.conf中
在/home/www/bbs目录下创建bbs_nginx.conf文件并写入以下代码:
1 2 3 |
|
然后在上面的代码后面加上如下代码:
1 |
|
这样网站根目录中的bbs_nginx.conf伪静态规则,即可实现单独管理。
下面是一个实例:
1. 在使用.htaccess文件的目录下新建一个.htaccess文件,如下面一个Discuz论坛目录:
1 |
|
2. 在里面输入规则,我这里输入Discuz的伪静态规则(这里仅增加Discuz的伪静态规则):
1 2 3 4 5 6 7 8 |
|
wq保存退出。
3. 修改nginx配置文件:
1 |
|
4. 在需要添加伪静态的虚拟主机的server{}中引入.htaccess文件:
1 |
|
wq保存退出。
5. 重新加载nginx配置文件:
1 |
|
Nginx常用Rewrite伪静态规则:
伪静态规则是我们做伪静态的一个非常重的参数了,如果我们能理解得越多就可以快速的写出最优的伪静态代码了,下面给大家整理了一些例子,希望能给你有帮助。
本日志内容来自互联网和平日使用经验,整理一下方便日后参考。
正则表达式匹配,其中:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
一些可用的全局变量有,可以用做条件判断(待补全)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
结合QeePHP的例子
1 2 3 4 |
|
多目录转成参数
1 2 3 4 5 |
|
目录对换
1 2 3 4 5 6 |
|
目录自动加“/”
1 2 3 |
|
禁止htaccess
1 2 3 |
|
禁止多个目录
1 2 3 4 |
|
禁止以/data开头的文件
可以禁止/data/下多级目录下.log.txt等请求;
1 2 3 |
|
禁止单个目录
不能禁止.log.txt能请求
1 2 3 |
|
禁止单个文件
1 2 3 |
|
给favicon.ico和robots.txt设置过期时间;
这里为favicon.ico为99天,robots.txt为7天并不记录404错误日志
1 2 3 4 5 6 7 8 9 10 |
|
设定某个文件的过期时间;这里为600秒,并不记录访问日志
1 2 3 4 5 6 |
|
文件反盗链并设置过期时间
这里的return 412 为自定义的http状态码,默认为403,方便找出正确的盗链的请求
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
只允许固定ip访问网站,并加上密码
1 2 3 4 5 6 7 |
|
将多级目录下的文件转成一个文件,增强seo效果
1 2 |
|
将根目录下某个文件夹指向2级目录
如/shanghaijob/ 指向 /area/shanghai/
如果你将last改成permanent,那么浏览器地址栏显是/location/shanghai/
1 |
|
上面例子有个问题是访问/shanghai 时将不会匹配
1 2 |
|
这样/shanghai 也可以访问了,但页面中的相对链接无法使用,
如./list_1.html真实地址是/area/shanghia/list_1.html会变成/list_1.html,导至无法访问。
那我加上自动跳转也是不行咯
1 2 3 4 |
|
知道原因后就好办了,让我手动跳转吧
1 2 |
|
文件和目录不存在的时候重定向:
1 2 3 |
|
域名跳转
1 2 3 4 5 6 7 8 9 |
|
多域名转向
1 2 3 4 5 6 |
|
三级域名跳转
1 2 3 4 |
|
域名镜像
1 2 3 4 5 6 7 8 9 |
|
某个子目录作镜像
1 2 3 4 |
|
discuz ucenter home (uchome) rewrite
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
附现在常用cms替换
WordPress伪静态规则:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
PHPCMS伪静态规则:
1 2 3 4 5 6 7 8 9 |
|
ECSHOP伪静态规则:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
SHOPEX伪静态规则 :
1 2 3 4 5 |
|
SaBlog 2.0:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Discuz 7伪静态规则 :
1 2 3 4 5 |
|
Typecho:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
实例:shopex启用伪静态
1 2 3 4 5 6 7 |
|
相关文章:

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.
