htaccess to nginx

microz

Verified User
Joined
Jun 10, 2009
Messages
122
Location
Santiago, Chile
Hi,

I'm trying change from apache to nginx, but I need convert htaccess to nginx to work permlinks.

Code:
<IfModule mod_rewrite.c>
    RewriteEngine on

    # --- Redirect from http to https
    #RewriteCond %{HTTPS} off
    #RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # ---

    # --- Redirect from non-www to www
    #RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
    #RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
    # ---

    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
    RewriteRule ^.*$ %2index.php?page=$0&%{QUERY_STRING} [QSA,L]
</IfModule>

I'm use https://winginx.com/en/htaccess for convert and get.

Code:
location / {  if (!-e $request_filename){    rewrite ^(.*)$ /%2index.php?page=$0&$query_string break;  } }

Then when I add in Custom HTTPD configuration, the directadmin return:

Code:
nginx: [emerg] unknown "0" variable
nginx: configuration file /etc/nginx/nginx.conf test failed

Any suggestion? What should be the correctly args for replace in $0?

Thanks!
 
Last edited:
try another way - just find ready nginx rules fo your tasks:
- Redirect from http to https
- Redirect from non-www to www
- page redirect for (joomla/wp/drupal)? etc.
 
try another way - just find ready nginx rules fo your tasks:
- Redirect from http to https
- Redirect from non-www to www
- page redirect for (joomla/wp/drupal)? etc.

Thanks for your suggestions.

- 1 and 2 are ready with directadmin/domains config, then I not need this lines.
- 3 for brizy, can't found info about this.
 
Back
Top