Category Archives: nginx

htaccess mod Rewrite Rule – optional parameters

I want to rewrite the below:

  1. http://www.mywebsite/address/12345/ to http://www.mywebsite/address/?param1=12345
  2. http://www.mywebsite/address/12345/12 to http://www.mywebsite/address/?param1=12345&param2=12
  3. http://www.mywebsite/address/12345/?{otherparam}=1 to http://www.mywebsite/address/?param1=12345&{otherparam}=1

Below is what I have in the .htaccess file. I have the first two working fine yet am struggling with the 3rd. I need the third to pass param1 & moreover pass other optional parameters. Can anyone assist?

You’re looking for the QSA flag, which appends any existing query string to the newly constructed one in the rule’s target:

Nginx Reverse SSL Proxy with PHP

This trick introduce the way of creating nginx reverse SSL proxy that works with PHP in load balancing environment.

Example network structure


1. Nginx proxy config file for ssl connection
define upsteam in nginx.conf

define the

2. Web server behind the proxy
2.1. Install pecl_http extension with pecl install pecl_http. (This extension allow you to obtain headers from cgi mode, ideally for php-fpm)

2.2. In PHP script, use

To check if the request is from https

nginx rewrite rule for opencart

It took me a while to find out the solution, yet at last, I found it is pretty easy, the admin folder just need to take a bit extra care. This rewrite rule works moreover work with SEO url settings enabled.

Tested with opencart 1.5.13

nginx rewrite rule for codeigniter

This is my nginx configuration file, which obtain the assist from

Here are the few things you MUST take care:
1. All rewrite rule & root must set in server scope, NO location \{} nor ~\.php${} !!!
2. In codeigniter application/config/config.php file

  • set $config[‘index_page’] = “”;
  • set $config[‘uri_protocol’] = “REQUEST_URI”;

Here is the rewrite rule that you need

For more nginx rewrite rule, please visit

Nginx rewrite rule for Kohana

This took me a while to investigate how to set the rewrite rule for Kohana in nginx, then I found it is really easy