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路径即 ...
随机推荐
- Wpf 系列
http://www.cnblogs.com/chillsrc/category/684419.html
- Python学习---模版/包的概念
1.1. 模块/包的概念 在Python中,一个.py文件就称之为一个模块(Module) 模块一共三种: python标准库 第三方模块 应用程序自定义模块 模块的使用:模块是用来组织函数的 解释器 ...
- mysql多实例mysqld_multi方式
mysql多实例应用,亲测直接执行脚本可使用,可快速部署多实例环境 #!/bin/bash set -e #定义mysql_multi多实例数据的配置,如需增加,在后面函数对应地方需要增加 mydir ...
- ANT table表格合并
1. 合并前提 后台返回数据必须是:相同重复的数据必须是连在一起的,这样前台才能通过rowspan方法合并表格数据.(这是前提,后台需要注意) 2.步骤 1.前台需要根据后台返回的数据内容, ...
- [原]Linux 修改时区
1.查看当前时区 date -R 2.修改当前时区 tzselect 之后会出来一个选项菜单,选择你想要的时区就OK了 3.替换系统时区文件 cp /usr/share/zoneinfo/XXX/YY ...
- PHP中将字符串转化为整数(int) intval() printf()
int <?php $foo = "1"; // $foo 是字符串类型 $bar = (int)$foo; // $bar 是整型 ?> intval <?ph ...
- TunSafe使用分享
体验还是很棒的,关于使用中遇到的一些问题在此分享下 官网打不开? 这个真的很不解,科学以后遇到的, 后来在手机上同样的环境测试可以打开 最后居然使用ie浏览器解决了,看来是国产浏览器在作怪 ie终于打 ...
- springboot+mybatis+shiro——shiro简介
转载:[一]shiro入门 之 Shiro简介 一.shiro介绍: 官方网址:http://shiro.apache.org/introduction.html,shiro的功能包括:认证.授权.加 ...
- EasyPoi导入Excel
EasyPoi的导出Excel功能和导入功能同样简单.我之前强调过,EasyPoi的原理本质就是Poi,正如MyBatis Plus的本质原理就是MyBatis. POI导入功能可以参考如下地址:ht ...
- 二十五、详述 IntelliJ IDEA 提交代码前的 Code Analysis 机制
在我们用 IntelliJ IDEA 向 SVN 或者 Git 提交代码的时候,IntelliJ IDEA 提供了一个自动分析代码的功能,即Perform code analysis: 如上图所示,当 ...