apache上.htaccess转向nginx上配置.htaccess伪静态规则
在apache上.htaccess转向,只要apache编译的时候指明支持rewrite模块即可。
但是换到nginx上方法会有不同,有人说把.htaccess转向规则写到nginx的配置文件里面,官方提供的方法之一,肯定可行的。
不过,此方法有个问题:不方便,下次要更改一个伪静态转向规则的时候还得去nginx的配置文件或者nginx的虚拟网站的配置文件里面去改,相比apache直接在目录下放置.htaccess文件,nginx的这个办法显然很原始。
解决方法:
在nginx的配置文件中include .htacces文件就可以实现相同的功能了。
举个例子,要把www.jbxue.com的.htaccess迁移到nginx上,几个步骤:
第一步:修改.htaccess文件,因为apache的rewrite转向规则跟nginx的转向规则还是有一些不一样的,典型的不一样有nginx的根目录需要写在每行转向的地址前,每行规则必须以分号(;)结束,301或者404等跳转使用不同的格式。
apache上htaccess转换到nginx上:
RewriteEngine On
RewriteBase /
RewriteRule ^show-([-]+)-([-]+)\.html$ index.php?action=show&id=$&page=$
RewriteRule ^category-([-]+)-([-]+)\.html$ index.php?action=index&cid=$&page=$
RewriteRule ^archives-([-]+)-([-]+)\.html$ index.php?action=index&setdate=$&page=$
RewriteRule ^(archives|search|reg|login|index|links)\.html$ index.php?action=$
RewriteRule ^(comments|tagslist|trackbacks|index)-([-]+)\.html$ index.php?action=$&page=$
rewriteCond %{http_host} ^jbxue.com [NC]
rewriteRule ^(.*)$ http://www.jbxue.com/$1 [R=301,L]
ErrorDocument http://www.jbxue.com/
转换成nginx的规则
rewrite ^/show-([-]+)-([-]+)\.html$ /index.php?action=show&id=$&page=$;
rewrite ^/category-([-]+)-([-]+)\.html$ /index.php?action=index&cid=$&page=$;
rewrite ^/archives-([-]+)-([-]+)\.html$ /index.php?action=index&setdate=$&page=$;
rewrite ^/(archives|search|reg|login|index|links)\.html$ /index.php?action=$;
rewrite ^/(comments|tagslist|trackbacks|index)-([-]+)\.html$ /index.php?action=$&page=$;
if ($host != 'www.jbxue.com' ) {
rewrite ^/(.*)$ http://www.jbxue.com/$1 permanent;
}
error_page http://www.jbxue.com/;
第二步:修改nginx的配置文件,增加include该.htaccess文件
vi /etc/nginx/sites-available/www.jbxue.com
增加一行:include /var/www/www.jbxuecom/.htaccess
修改为相应的地址。
第三步:测试并重启
代码示例:
apache上.htaccess转向nginx上配置.htaccess伪静态规则的更多相关文章
- Nginx在windows上安装 及 Nginx的配置及优化
https://www.cnblogs.com/Chiler/p/8027167.html http://www.runoob.com/linux/nginx-install-setup.html 前 ...
- centos7 Apache开启URL重写组件并配置.htaccess实现伪静态
第一.修改httpd.conf文件 A - 在etc/httpd/conf/目录下的httpd.conf 文件,找到: LoadModule rewrite_module modules/mod_re ...
- tp5 url 线上访问 在nginx 上 出现404错误,解决办法(1.80nginx 配置 pathInfo)
对于ThinkPHP的URL访问路劲如:http://域名/index.php/Index/BlogTest/read,原先的Nginx的是不支持的pathinfo路劲的,导致你在thinkPHP ...
- Apache、tomcat、Nginx常用配置合集
配置文件地址: Apache: /etc/httpd/conf/httpd.conf tomcat: /usr/local/tomcat/conf/server.xml Nginx : /usr/l ...
- Apache模块mod_security 和 Nginx过滤配置
1.安装mod_securityyum install mod_security 2.安装mod_security_crsyum install mod_security_crs 3.在/etc/ht ...
- tp5 apache 转 nginx 需要配置的伪静态
location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$ last; break; } }
- centos nginx server_name 配置域名访问规则
今天配置Server_name时,希望禁用一些域名,应为这些域名我想让通过另外一个Server配置 server_name "~^((\w*[^w]{1}\w*)|w{1,2})\.hell ...
- 通过ngx-lua来统计Nginx上的虚拟主机性能数据
Web server调研分析 Filed under: Web Server — cmpan @ 2012-10-29 20:38:34 摘要 简单可依赖的架构首先需要有一个简单可依赖的前端WebSe ...
- Nginx Location配置总结
Nginx Location配置总结 语法规则: location [=|~|~*|^~] /uri/ { - }= 开头表示精确匹配^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即 ...
随机推荐
- mongodb 3.4复制搭建
mongodb数据库主从复制的原理:在主从结构中,主节点的操作记录称为oplog(operation log).oplog存储在一个系统数据库local的集合oplog.$main中,这个集合的每个文 ...
- io问题导致的insert缓慢
生产环境一日常insert在业务量加倍之后非常缓慢,对有问题sql做awr报告和10046trace得出以下结论:In the 10046 trace, the execution of sql el ...
- C/C++ 合法整数与字符
一.C语言中的合法整型 首先C语言中的整型有三种表示方式:十进制.八进制和十六进制.(C语言中没有表示二进制的整型) 十进制: 如 int a = 63; //一个正常的整型 八进制: 如果想用8进制 ...
- 一、异步编程模型(APM)
一.概念 APM即异步编程模式的简写(Asynchronous Programming Model).大家在写代码的时候或者查看.NET 的类库的时候肯定会经常看到和使用以BeginXXX和EndXX ...
- C语言编译器,写给萌新们看看。
就我已经经历过的大学课程,仿佛每一门计算机的专业课程的开头,都是在介绍计算机发展的历史,和大名鼎鼎的冯诺依曼结构. 譬如C语言,比较水的计算机导论,c++,数据结构,计算机组成原理,甚至是Linux实 ...
- 记录linux查询命令的一个网站
http://man.linuxde.net/ 另外下面是对常用命令的总结 https://www.cnblogs.com/soyxiaobi/p/9717483.html
- php 处理微信账单
最近要做支付对账,即检查第三方支付与数据库中账单是否一一对应,涉及到微信对账单的处理,微信账单接口返回为一个字符串类似如下结果: 交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单 ...
- Avito Cool Challenge 2018 E. Missing Numbers 【枚举】
传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...
- performPeriodicTask
/********************************************************************* * @fn performPeriodicTask 执行 ...
- 确保img的宽高比固定
html: <div class="wrapper"> <swiper :options="swiperOption"> <swi ...