Rewrite rule for nginx from Apache

Denis F. Latypoff denis at gostats.ru
Wed Nov 18 18:28:47 MSK 2009


Hello Robert,

Wednesday, November 18, 2009, 9:17:23 PM, you wrote:

> Can anyone tell me how to rewrite this rules from apache:

> RewriteEngine On
> RewriteRule ^shorten/(.*)$ shorten.php?longurl=$1 [L]
> RewriteRule ^([0-9a-zA-Z]{1,6})$ redirect.php?url=$1 [L]

> to nginx?

> Thanks!

location ~ ^/shorten/(?<longurl>.*)$ {
    root ...;
    fastcgi_pass ...;
    fastcgi_param SCRIPT_NAME     /shorten.php;
    fastcgi_param SCRIPT_FILENAME $document_root/shorten.php;
    fastcgi_param QUERY_STRING    longurl=$longurl;
}

location ~ "^/(?<url>[0-9a-zA-Z]{1,6})$" {
    root ...;
    fastcgi_pass ...;
    fastcgi_param SCRIPT_NAME     /redirect.php;
    fastcgi_param SCRIPT_FILENAME $document_root/redirect.php;
    fastcgi_param QUERY_STRING    url=$url;
}

-- 
Best regards,
 Denis                            mailto:denis at gostats.ru






More information about the nginx mailing list