Convert htaccess file to nginx config file.
June 02, 2019 06:44AM
I tried convert .htaccess file to nginx config file. Here is .htaccess file.

RewriteEngine On

RewriteCond /var/www/html/usluno/coopshop/$1/$2 -f
RewriteRule (bin|html|libs)/((.*)\.(htm|html|js|gif|jpg|png|css|ico|php|woff|svg|ttf|eot|pdf)$)/var/www/html/usluno/coopshop/$1/$2 [NC,L]

RewriteRule \.(htm|html|js|gif|jpg|png|css|ico|php|pdf)$ - [NC,L]

(tmp/backend|tmp/frontend|libs|html/templates|mods|_htaccess|_sql) - [NC,L,F]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+[^/])$ /$1/ [R=301,L,QSA,NE]

RewriteCond %{HTTP_HOST} !^coopshop.local
RewriteRule (.*) http://coopshop.local/$1 [R=301,QSA,L]

RewriteRule ^t([a-zA-Z0-9]{32})\/$ /customer/password/?action=3&token=$1 [R=301,L,QSA,NC]

# Prepis na controller/dispatcher
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ /controller.php?MRW_CONTROLLER_URI=$1&MRW_CONTROLLER_HOST=%{HTTP_HOST} [L,QSA,NC]

I tried to convert with online converter. Here is converted nginx config file.

# nginx configuration

location ~ \.(htm|html|js|gif|jpg|png|css|ico|php|pdf)$ {
try_files $uri $uri/ /index.php?$args;

location ~ (tmp/backend|tmp/frontend|libs|html/templates|mods|_htaccess|_sql) {
return 403;

location / {
rewrite (bin|html|libs)/((.*)\.(htm|html|js|gif|jpg|png|css|ico|php|woff|svg|ttf|eot|pdf)$) /var/www/html/usluno/coopshop/$1/$2 break;
if (!-e $request_filename){
rewrite ^/(.+[^/])$ /$1/ redirect;
if ($http_host !~ "^coopshop.local"){
rewrite ^(.*)$ http://coopshop.local/$1 redirect;
rewrite "^/t([a-zA-Z0-9]{32})\/$" /customer/password/?action=3&token=$1 redirect;
if (!-e $request_filename){
rewrite ^/(.*?)/?$ /controller.php?MRW_CONTROLLER_URI=$1&MRW_CONTROLLER_HOST=$http_host break;

Home page is working, but when I click on link on page, it download PHP file instead of load the page.

Here is my vhost config.

server {
listen 80;
listen [::]:80;
server_name php56.coopshop.local;
root /var/www/html/usluno/php56/coopshop;
index index.php;
location ~* \.php$ {
# With php-fpm unix sockets
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
try_files $uri $uri/ /index.php?$args;
location ~ /\.ht {
deny all;
access_log /var/log/nginx/php56_coopshop_access.log;
error_log /var/log/nginx/php56_coopshop_error.log;
include /var/www/html/usluno/php56/coopshop/nginx.conf;

Of course I add domain to my hosts. php56.coopshop.local

Where could be the problem? Thank you very much for every idea!


Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 196
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready