Convert htaccess to nginx

Does this look right?


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}


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

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;


Please enter an answer

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] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct