Answer the question
In order to leave comments, you need to log in
How can I convert .htaccess to work in Nginx?
Hello.
The crux of the matter is this.
I have an Nginx + php-fpm server, I'm trying to install the script, it basically works, but some of the links don't work.
.htaccess looks like this:
AddType image/x-icon .ico
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
Options +FollowSymlinks
Options -Indexes
RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_URI} \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml|zip|txt|doc)$
RewriteRule ^(.*) $1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} \.(ini|ph.*)$
RewriteRule ^(.*) index.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L,QSA]
</IfModule>
<IfModule mod_php5.c>
php_flag magic_quotes_gpc Off
</IfModule>
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
if ($request_uri ~ "\.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml|zip|txt|doc)$"){
rewrite ^/(.*) /$1 break;
}
if (!-e $request_filename){
rewrite ^/(.*) /index.php;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
Answer the question
In order to leave comments, you need to log in
I know the best tool - the brain.
1. Read and understand what .htaccess does
2. Write the necessary lines in the nginx config.
Reading:
RewriteCond %{REQUEST_URI} \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml|zip|txt|doc)$
RewriteRule ^(.*) $1 [QSA,L]
location ~ \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml|zip|txt|doc)$ {
# ничего не нужно, просто отдаём файлы
}
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} \.(ini|ph.*)$
RewriteRule ^(.*) index.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L,QSA]
location / {
try_files $uri /index.php;
}
# скорее всего нужно что-то типа \.(ini|php|phps|php4|php5)$
# или хотя бы \.(ini|ph\w*)$
location ~ \.(ini|ph.*)$ {
rewrite ^ /index.php break;
fastcgi_pass 127.0.0.1:9002;
# и прочие fastcgi_*
}
location / {
try_files $uri /index.php;
}
location ~ \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml|zip|txt|doc)$ {
# ничего не нужно, просто отдаём файлы
}
location ~ \.(ini|ph.*)$ {
rewrite ^ /index.php break;
fastcgi_pass 127.0.0.1:9002;
# и прочие fastcgi_*
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question