Please convert this mod rewrite rule

Igor Sysoev igor at sysoev.ru
Tue Apr 12 10:19:30 MSD 2011


On Mon, Apr 11, 2011 at 06:15:09PM -0400, alex1950 wrote:
> Hi, 
> 
> <IfModule mod_rewrite.c>
> # Tell PHP that the mod_rewrite module is ENABLED.
> 
> 	SetEnv HTTP_MOD_REWRITE On
> 	Options +FollowSymLinks
> 	RewriteEngine on
> 	RewriteRule test-(.*)\.htm$ inc/tesmodrewite.php?q=test_$1
> 	RewriteRule test2-(.*)\.htm$ /inc/tesmodrewite.php?q=test_$1
> 	RewriteRule pm-(.*)\.(jpg|png|gif|html)$ index.php?pm=$1
> 	RewriteRule pt-(.*)\.(jpg|png|gif|html)$ index.php?pt=$1
> 	RewriteRule dt-(.*)\.(jpg|png|gif)$ index.php?dt=$1
> 	RewriteRule dm-(.*)\.(jpg|png|gif)$ index.php?dm=$1
> 	RewriteRule di-(.*)\.(jpg|jpeg|png|gif|bmp)$ index.php?di=$1
> 	RewriteRule page(.*)\.html$ gallery.php?p=$1
> </IfModule>

If you want to use configuraiton which will be easy to maintain in future,
do not use rewrite's:

    location /test- {
         location ~ ^/test-(.+)\.htm$ {
             fastcgi_pass   ...
             fastcgi_param  SCRIPT_FILENAME  /path/to/inc/tesmodrewite.php;
             fastcgi_param  QUERY_STRING     q=test_$1;
             ...
         }
    }

    location /test2- {
         location ~ ^/test2-(.+)\.htm$ {
             fastcgi_pass   ...
             fastcgi_param  SCRIPT_FILENAME  /path/to/inc/tesmodrewite.php;
             fastcgi_param  QUERY_STRING     q=test_$1;
             ...
         }
    }

Yes, the configuration will be larger, but every location is independent
and may be changed or new locations may be added without worry how it
will affect other parts of the configuration.


-- 
Igor Sysoev



More information about the nginx mailing list