.htaccess转nginx规则在线工具

现在虚拟主机一般采用Apache,而vps的主流是安装基于nginx的lnmp集成包,网站在虚拟主机和VPS间搬家,经常会对.htaccess转nginx伪静态规则很头疼。

国外一个网站提供了一个在线.htaccess转nginx规则的工具,测试了一下很方便,将.htaccess规则下载左面,点击convert,右面就会出现nginx规则,把规则写入nginx.conf就能使网站正常访问了!

工具地址为:http://www.anilcetin.com/convert-apache-htaccess-to-nginx/
备用地址:http://www.anilcetin.com/

PS:

部分写的不咋规范的.htaccess可能需要手动修正,本博提供有限技术支持(时间和环境允许)!

END

《.htaccess转nginx规则在线工具》上有37条评论

      1. 我自己也转换了,能用! 不过重启lnmp的时候提示:nginx: [warn] conflicting server name “img.aalun.com” on 0.0.0.0:80, ignored
        Nginx start successfully!

        貌似是说什么什么重名了,不太懂!完整点是这样的:
        Stoping LNMP…
        Nginx program is stop
        Shutting down php_fpm . done
        PHP-FPM program is stop
        Shutting down MySQL…. SUCCESS!
        MySQL program is stop
        Starting LNMP…
        nginx: [warn] conflicting server name “img.aalun.com” on 0.0.0.0:80, ignored
        Nginx start successfully!
        Starting php_fpm done
        PHP-FPM start successfully!
        Starting MySQL. SUCCESS!
        MySQL start successfully!
        [root@307700 exif]#

        1. 程序自带.htaccess文件! 文件全部内容如下:
          # ———————————————————————-
          # gzip compression
          # ———————————————————————-

          # force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/

          SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)s,?s(gzip|deflate)?|X{4,13}|~{4,13}|-{4,13})$ HAVE_Accept-Encoding
          RequestHeader append Accept-Encoding “gzip,deflate” env=HAVE_Accept-Encoding

          # html, txt, css, js, json, xml, htc:

          FilterDeclare COMPRESS
          FilterProvider COMPRESS DEFLATE resp=Content-Type /text/(html|css|javascript|plain|x(ml|-component))/
          FilterProvider COMPRESS DEFLATE resp=Content-Type /application/(javascript|json|xml|x-javascript)/
          FilterChain COMPRESS
          FilterProtocol COMPRESS change=yes;byteranges=no

          # Legacy versions of Apache
          AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
          AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
          AddOutputFilterByType DEFLATE text/xml application/xml text/x-component

          # ———————————————————————-
          # Expires headers (for better cache control)
          # ———————————————————————-

          ExpiresActive on

          # Perhaps better to whitelist expires rules? Perhaps.
          ExpiresDefault “access plus 1 month”

          # cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
          ExpiresByType text/cache-manifest “access plus 0 seconds”

          # your document html
          ExpiresByType text/html “access plus 0 seconds”

          # data
          ExpiresByType text/xml “access plus 0 seconds”
          ExpiresByType application/xml “access plus 0 seconds”
          ExpiresByType application/json “access plus 0 seconds”

          # rss feed
          ExpiresByType application/rss+xml “access plus 1 hour”

          # favicon
          ExpiresByType image/x-icon “access plus 1 week”

          # media: images
          ExpiresByType image/gif “access plus 1 month”
          ExpiresByType image/png “access plus 1 month”
          ExpiresByType image/jpg “access plus 1 month”
          ExpiresByType image/jpeg “access plus 1 month”

          # css and javascript
          ExpiresByType text/css “access plus 2 months”
          ExpiresByType application/javascript “access plus 2 months”
          ExpiresByType text/javascript “access plus 2 months”

          Header append Cache-Control “public”

          # ETag removal
          FileETag none

          RewriteEngine on
          ErrorDocument 400 /index.php?err=400
          ErrorDocument 401 /index.php?err=401
          ErrorDocument 403 /index.php?err=403
          ErrorDocument 404 /index.php?err=404
          ErrorDocument 500 /index.php?err=500
          #image view
          RewriteRule ^pm-(.*).(jpg|jpeg|png|gif|html)$ thumbnail.php?pm=$1 [L]
          RewriteRule ^pt-(.*).(jpg|jpeg|png|gif|html)$ thumbnail.php?pt=$1 [L]
          RewriteRule ^dt-(.*).(jpg|jpeg|png|gif)$ image.php?dt=$1 [L]
          RewriteRule ^dm-(.*).(jpg|jpeg|png|gif)$ image.php?dm=$1 [L]
          RewriteRule ^di-(.*).(jpg|jpeg|png|gif|bmp)$ image.php?di=$1 [L]
          RewriteRule ^dl-(.*).(jpg|jpeg|png|gif|bmp)$ image.php?dl=$1 [L]

          RewriteRule ^pm/(.*)/(.*).(jpg|jpeg|png|gif|html)$ thumbnail.php?pm=$1 [L]
          RewriteRule ^pt/(.*)/(.*).(jpg|jpeg|png|gif|html)$ thumbnail.php?pt=$1 [L]
          RewriteRule ^dt/(.*)/(.*).(jpg|jpeg|png|gif)$ image.php?dt=$1 [L]
          RewriteRule ^dm/(.*)/(.*).(jpg|jpeg|png|gif)$ image.php?dm=$1 [L]
          RewriteRule ^di/(.*)/(.*).(jpg|jpeg|png|gif|bmp)$ image.php?di=$1 [L]
          RewriteRule ^dl/(.*)/(.*).(jpg|jpeg|png|gif|bmp)$ image.php?dl=$1 [L]
          #Not Found
          RewriteRule ^(pm|pt)/(.*)/(.*)$ thumbnail.php?pm=notfound [L]
          RewriteRule ^(dt|dm|di|dl)/(.*)/(.*)$ index.php?di=notfound [L]

          #Gallery
          RewriteRule ^gallery/$ gallery.php [L]
          RewriteRule ^gallery/([0-9]+)/$ gallery.php?p=$1 [L]
          RewriteRule ^gallery/(.*)/([0-9]+)/$ gallery.php?p=$2&o=$1 [L]
          RewriteRule ^gallery/([A-Za-z])/page([0-9]+).html$ gallery.php?p=$2&o=$1 [L]
          #sitemap
          RewriteRule ^sitemap.xml$ sitemap.php [L]

          我根据这个文件转换后的规则可以用,但lnmp重启会提示重名什么的。。 不懂! 有可能我转换的有问题。。
          博主有时间可以帮我转换下。。

          1. 缓存类的可以删除…军哥的lnmp默认缓存和gzip…
            而且前面的错误貌似跟规则没关系…
            请检查/usr/local/nginx/conf/vhost/下所有的主机头,用cat命令…

  1. 猪三戒感谢你访问,猪猪语:我们的每一天都是新鲜的一天,每天都不是重复的一天,将每一天都过得开心快乐,年轻不是年轮的加减去除而是积极乐观的心态,如果你年方18但是心态已老去,那么你也将不再年轻,如果你已81岁高龄却是每天奋斗积极、开心乐观,那么你依然是年轻人,正如文胜(文胜:人生总会碰上些意外之事,看起来是偶然,发生了就是必然。不必遗憾,错过或许是种另外的美好!)所说那样,猪三戒感悟人生不必太在乎伤心的过往,而应该珍惜今天,奋斗今天,加油,期待你再次造访。

        1. 你不懂啊…
          1024M内存的100/月我也不敢买…
          但128M或256M内存的30-100每月我绝对买…
          要看配置…而且不是配置越高越好…而且母鸡跟超售严不严重…

回复 Xider 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注