0

1.) Apache Rule:

RewriteRule ^(.*)/(.*).htm$ /inner.php?Categories=$0&Title=$1 [L,QSA]

2.) After converting to nginx:

rewrite ^/(.*)/(.*).htm$ /inner.php?Categories=$0&Title=$1 break;

Question: When user access this page http://example.com/category.htm and tried to click inside the pages means it should be redirect into http://example.com/category/innerpagetitle.htm/

How do i achieve in nginx?

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63

2 Answers2

1

In nginx variables are returned starting from $1 so this should work:

rewrite ^/(.*)/(.*).htm$ /inner.php?Categories=$1&Title=$2 break;
Simon Greenwood
  • 1,363
  • 9
  • 12
1

I prefer to implement these using location blocks.

location ~ ^/(.+)/(.+)\.htm$ {
    try_files $uri $uri/ /inner.php?Categories=$1&Title=$2;
}

I also changed from .* (0 matches or more) to .+ (1 matches or more) to avoid possible undefined behaviour from the PHP script.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63