Apache to Nginx Conversion Issue with .htaccess

I am trying to migrate a Apache website into fully Nginx powered with PHP-FPM.

However when i try to convert following complicated rules set on the .htaccess file for Apache all my attempts with Online converters failed with errors.

Is there any one who can help me with this ?

#ModPagespeed on
Options -indexes
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# BEGIN Rewrite
<IfModule mod_rewrite.c>
RewriteEngine on 
RewriteBase /

RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} s/+(?:index.php)??search=([^s&]+) [NC]
RewriteRule ^ /%1/? [R=302,L,NE]
## replace of space with -
# executes **repeatedly** as long as there are more than 1 spaces in URI
RewriteRule "^(S*) +(S* .*)$" /$1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^(S*) (S*)$" /$1-$2? [L,R=302,NE]

RewriteRule ^search/([^/]+)/page/([^/]+)$ index.php?search=$1&page=$2
RewriteRule ^article/([^/]+)/([^/]+)/$ index.php?layout=article&id=$1

RewriteRule ^adwords/([^/]+)$ adwords/$1 [L]

RewriteRule ^images/([^/]+)$ images/$1 [QSA,L]
RewriteRule ^images/([^/]+)/([^/]+)$ images/$1/$2 [QSA,L]

RewriteRule ^ajax/([^/]+)$ ajax/$1 [QSA,L]

RewriteRule ^info/([^/]+)$ info/$1 [QSA,L]
RewriteRule ^reports/([^/]+)$ reports/$1 [QSA,L]

RewriteRule ^css/([^/]+)$ css/$1 [QSA,L]
RewriteRule ^css/([^/]+)/([^/]+)$ css/$1/$2 [QSA,L]

RewriteRule ^includes/([^/]+)$ includes/$1 [QSA,L]
RewriteRule ^includes/([^/]+)/([^/]+)$ includes/$1/$2 [QSA,L]

RewriteRule ^reports/([^/]+)$ reports/$1 [QSA,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ ?search=$1 [QSA,L]
# END Rewrite

If i convert this with below converter i get error

Invalid nginx configuration: nginx: [emerg] invalid variable name in /var/www/vhosts/system/example.com/conf/vhost_nginx.conf:12 nginx: configuration file /etc/nginx/nginx.conf test failed 

Source: .htaccess

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.