How to convert Apache rewrites for nginx

This is an article of mine first published on Wazi.
Apache is still by far the most widely deployed HTTP server, according to the latest Netcraft web server survey, but nginx has been slowly, steadily gaining market share, thanks to its blazing speed. If you want to try a faster web server and move from Apache to nginx, you’ll probably have to change some of your websites’ configurations, starting with rewrite directives. To migrate rewrite rules from Apache to nginx, start with these tips and tricks.
The Apache mod_rewrite module provides powerful and sophisticated tools for nearly all types of URL rewriting. It is, however, somewhat complex, and may be intimidating to beginners. In fact, however, rewrite rules are not magical incantations, though to understand them you need some understanding of regular expressions.
Even if you have never heard of mod_rewrite, you may still be using it. Popular applications such as WordPress, Drupal, and Magento are shipped with .htaccess files that contain standard configurations that make these applications work properly, and these usually include one or more rewrites, so to properly move your website to an nginx web server you have to “translate” the Apache mod_rewrite directives into equivalent rules for nginx’s HttpRewriteModule.

How to verify if you are using mod_rewrite in Apache with PHP
If you dont know if you your website is using mod_rewrite or not, and you want to do a further check you can use this approach:
1) In your document root,the directory where you have all your html files, add (or modify if it already exists) a file with name .htaccess that must contains these lines:
// Tell PHP that the mod_rewrite module is ENABLED.
SetEnv HTTP_MOD_REWRITE On
2) In your document root add a second file, with name check_rewrite.php with the following content:
n”;
} else {

Read more at Linux Aria

Comments are closed.