Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert htaccess to nginx [closed]

Tags:

I'm having no luck converting htaccess rules to nginx rewrite. I've checked out the NginxRewriteModule documentation and have a few done, but the more complicate ones I'm at a loss for. Here's what I'm looking at:

RewriteRule    ^$                                               /cgi-bin/index.cgi [L] RewriteRule    ([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$         /cgi-bin/index.cgi?del=$1-$2 [L]  RewriteCond     %{REQUEST_FILENAME} !-f  RewriteRule    ^([0-9A-Za-z]{12})(\.html?|$)$                   /cgi-bin/index.cgi?op=download1&id=$1 [L] RewriteRule    ^([0-9A-Za-z]{12})(\/.+|\.html?|$)               /cgi-bin/index.cgi?op=download1&id=$1&fname=$2 [L] RewriteRule    ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$   /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2 [L] RewriteRule    ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$)        /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3 [L]  #RewriteRule    ^Reseller\.html$                                         /cgi-bin/Templates/Pages/english/Reseller.html [L] RewriteRule    ^checkfiles\.html$                                       /cgi-bin/index.cgi?op=checkfiles [L] RewriteRule    ^contact\.html$                                          /cgi-bin/index.cgi?op=contact [L] RewriteRule    ^premium\.html$                                          /cgi-bin/index.cgi?op=payments [L] RewriteRule    ^login\.html$                                            /cgi-bin/index.cgi?op=login [L] RewriteRule    ^catalogue(.*)\.html$                                    /cgi-bin/index.cgi?op=catalogue&date=$1 [L] RewriteRule    ^news([0-9]*)\.html$                                     /cgi-bin/index.cgi?op=news&page=$1 [L] RewriteRule    ^n([0-9]+)-.*\.html$                                     /cgi-bin/index.cgi?op=news_details&news_id=$1 [L] RewriteRule    ^free([0-9]+)\.html$                     /cgi-bin/index.cgi?op=registration&aff_id=$1 [L] RewriteRule    ^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$)        /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2 [L,NC] RewriteRule    ^embedmp3-([0-9A-Za-z]{12})\.html$   /cgi-bin/index.cgi?op=mp3_embed&file_code=$1 [L] RewriteRule    ^embedmp4-([0-9A-Za-z]{12})\.html$   /cgi-bin/index.cgi?op=mp32_embed&file_code=$1 [L] RewriteRule    ^box$                                    /cgi-bin/index_box.cgi [L]  RewriteCond     %{REQUEST_FILENAME} !-f RewriteCond     %{REQUEST_FILENAME} !-d RewriteRule    ^([0-9A-Za-z\-_]{4,64})(/[^\/]*/?|$)$            /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld=$2 [L,NC]  RewriteCond     %{REQUEST_FILENAME} !-f RewriteRule    ^([a-z0-9\-\_]+).html(.*)                        /cgi-bin/index.cgi?op=page&tmpl=$1$2 [L] 
like image 307
cheifops Avatar asked Apr 30 '11 08:04

cheifops


People also ask

Does htaccess work in nginx?

Nginx does not use . htaccess files like Apache does. This means that configuration previously done in . htaccess files now has to be done in a different format, explained in the Nginx documentation.

What is htaccess nginx?

htaccess for nginx enables the nginx high performance webserver to deal with . htaccess files. . htaccess files are mainly used for access control and URL rewrite instructions and are widely known across the web community.

Where is nginx conf located?

NGINX Configuration: Understanding Directives. Every NGINX configuration file will be found in the /etc/nginx/ directory, with the main configuration file located in /etc/nginx/nginx. conf .


1 Answers

Online tools to translate Apache .htaccess to Nginx rewrite tools include:

  • http://winginx.com/htaccess
  • http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

Note that these tools will convert to equivalent rewrite expressions using if statements, but they should be converted to try_files. See:

  • http://wiki.nginx.org/NginxHttpCoreModule#try_files
like image 119
Alex Dean Avatar answered Nov 21 '22 13:11

Alex Dean