Answer the question
In order to leave comments, you need to log in
Is there a file equivalent of .htaccess for nginx and lighttpd?
hello! I'm interested in this:
Apache has a .htaccess file, which is usually located in the root folder of the site. Is there a similar way (writing the appropriate settings in a separate file a la htaccess) for Nginx and LightTPD servers?
I tried to "google" and "yandexit" - I did not really find anything. :(
Answer the question
In order to leave comments, you need to log in
On Nginx, this is all done via nginx.conf . All rules are written there. If you have .htaccess, then you can convert Apache instructions to Nginx, for example, using this service . Everything is solved.
We have development on apache and production / dev servers on nginx.
As a result, we assembled a mini script to automate the conversion:
In the nginx config, we included a separate file into which we write the updated code from the script.
We do not use specific instructions, so all code is conditionally
$htaccess = file('.htaccess');
foreach ($htaccess as $line)
{
if (substr($line,0,11) == 'RewriteRule')
{
$line = str_replace('RewriteRule ^','rewrite ^/',$line);
$line = str_replace('[QSA,L]','last;',$line);
echo $line, "\n";
}
}
server {
server_name mysite.com;
set $site_root '/www/mysite.com';
...
include /etc/nginx/conf.d/mysite.com-rewrite.inc;
...
}
php _redirect_maker.php > /etc/nginx/conf.d/mysite.com-rewrite.inc
service nginx reload
there are no analogues
litespeed supports .htaccess from Apache but it is paid
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question