.htAccess和httpd.ini和Nginx之间的伪静态规则互相转换方法
经常换服务器,所以这些规则也需要互转。查询了很多,百度谷歌了也一堆,没有一个说明的文档,特自己趁热打铁把刚刚研究的成果记下来 已备以后查询!
httpd.ini 举例一个
-----------------------------------------------------------------------------------------------------------
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# duoduo Rewrite规则
RewriteRule ^/index.html$ /index.php
RewriteRule ^/sitemap.html$ /sitemap.php
RewriteRule ^/malllist.html$ /malllist.php
-----------------------------------------------------------------------------------------------------------
转换成 .htaccess 注意看不同点 下次按照这样转换即可。
-----------------------------------------------------------------------------------------------------------
RewriteEngine On
RewriteBase /
# duoduo Rewrite规则
RewriteRule index.html$ /index.php
RewriteRule sitemap.html$ /sitemap.php
RewriteRule malllist.html$ /malllist.php
-----------------------------------------------------------------------------------------------------------
httpd.ini 转换 .htaccess 一般规则说明:
1.
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
换成:
RewriteEngine On
RewriteBase /
2.
RewriteRule ^/index.html$ /index.php
去掉 ^/
RewriteRule index.html$ /index.php
-----------------------------------------------------------------------------------------------------------
.htaccess 转换成 nginx 注意看不同点 下次按照这样转换即可。
-----------------------------------.htaccess-----------------------------------------------------
RewriteEngine On
RewriteBase /
# duoduo Rewrite规则
RewriteRule index.html$ /index.php
RewriteRule sitemap.html$ /sitemap.php
RewriteRule malllist.html$ /malllist.php
------------------------------------nginx----------------------------------------------------------
location / {
rewrite /index.html$ /index.php last;
rewrite /sitemap.html$ /sitemap.php last;
rewrite /malllist.html$ /malllist.php last;-
----------------------------------------------------------------------------------------------------------
.htaccess 转换成 nginx 说明
-----------------------------------------------------------------------------------------------------------
1.
RewriteEngine On
RewriteBase /
# duoduo Rewrite规则
转换为:
location / {
2.
RewriteRule index.html$ /index.php
转换为:
rewrite /index.html$ /index.php last;
-----------------------------------------------------------------------------------------------------------
送上在线转换的地方:
.htaccess Editor :http://www.htaccesseditor.com/sc.shtml
把.htaccess中的规则自动转换成nginx
http://www.anilcetin.com/convert-apache-htaccess-to-nginx/
综合转换:http://www.onexin.net/rewrite.php
不可思议,将URL Rewrite规则正向或反向转换,适用于Apache,Lighttpd,IIS,Nginx环境下伪静态。
示例:
Nginx rewrite references e.g.
rewrite ^/(.*)([^/])$ http:
//$host/$1$2/ permanent;
Apache rewrite e.g.
RewriteRule ^store-([0-9]+)\.html$ store.php?id=
$1
[L,NC]
IIS rewrite (WordPress)
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Apache rewrite (WordPress)
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Nginx rewrite (Wordpress)
location / {
index index.html index.php;
if
(-f
$request_filename
/index.html){
rewrite (.*)
$1
/index.html
break
;
}
if
(-f
$request_filename
/index.php){
rewrite (.*)
$1
/index.php;
}
if
(!-f
$request_filename
){
rewrite (.*) /index.php;
}
}
相关文章:http://www.cpoo.com.cn/article/show_103.html