Convert htaccess to nginx

Does this look right?

htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([a-zA-Z0-9-]+)/?([a-zA-Z0-9-]+)?/?([0-9]{1,2}.[0-9]{2,3})?/?$ index.php?l=$1&s=$2&c=$3&q=%{QUERY_STRING}

nginx

location / {

if (!-e $request_filename){

rewrite "^/([a-zA-Z0-9-]+)/?([a-zA-Z0-9-]+)?/?([0-9]{1,2}.[0-9]{2,3})?/?$" /index.php?l=$1&s=$2&c=$3&q=$query_string;

}

}

1 Reply

You should avoid "if" with Nginx. See http://wiki.nginx.org/IfIsEvil

I think this will work, but it's been awhile since I've used Nginx:

location / {
    try_files $uri $uri/ @router;
}

location @router {    
     rewrite "^/([a-zA-Z0-9\-]+)/?([a-zA-Z0-9\-]+)?/?([0-9]{1,2}\.[0-9]{2,3})?/?$" /index.php?l=$1&s=$2&c=$3&q=$query_string;
}

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct