.htaccess to nginx

12
D
На сайте с 28.06.2008
Offline
1101
762

Перевожу один сайт с апача на Nginx, вроде перенес, но при навигации по сайту вижу только главную, хотя адреса урла меняются.

В .htaccess есть запись

# Rewrite all other URLs to index.php/URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [L]

Сервис https://winginx.com/ru/htaccess преобразовал ее в

location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php/$0 break;
}
}

Но при тестировании конфигурации идет сообщение об ошибке

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

Что не так? Пробовал 0 заменить на 1 - тогда на всех страницах получаю 404 ошибку, кроме главной

lonelywoolf
На сайте с 23.12.2013
Offline
151
#1
RewriteRule .* index.php/$0

Вот здесь ноль откуда взялся?

---------- Добавлено 25.07.2019 в 18:35 ----------

Используйте $uri или $request_uri вместо $0

Платный и бесплатный хостинг с защитой от DDoS (http://aquinas.su)
D
На сайте с 28.06.2008
Offline
1101
#2

Попробовал, теперь на всех кроме главной 404

lonelywoolf
На сайте с 23.12.2013
Offline
151
#3

Dram, У Nginx нельзя использовать $0, и меняется оно на то, что я сказал, больше не на что, насколько я понимаю из документации. Вообще правило должно выглядеть так:

location ~ / {

return 301 /index.php$request_uri;

}

# Try first the actual files, if they do not exist, then try $request_uri via `index.php`.

try_files $uri $uri/ /index.php/$request_uri;

D
На сайте с 28.06.2008
Offline
1101
#4

location ~ / {

return 301 /index.php$request_uri;

}

дает бесконечную переадресацию...

lonelywoolf
На сайте с 23.12.2013
Offline
151
#5
# Turn on URL rewriting
RewriteEngine On

RewriteBase //

# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# List of files in subdirectories will not be displayed in the browser
Options -Indexes

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

AddDefaultCharset utf-8
AddCharset UTF-8 .htm .html .txt
AddType "text/html; charset=UTF-8" .htm .html .txt
AddType "text/css; charset=UTF-8" .css
AddType "text/javascript; charset=UTF-8" .js

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

В оригинале было это?

Тогда надо

charset utf-8;
autoindex off;

location ~ /\.* {
deny all;
}

location ~ /(?:application|modules|system) {
return 301 /index.php$request_uri;
}

# Try first the actual files, if they do not exist, then try $request_uri via `index.php`.
try_files $uri $uri/ /index.php/$request_uri;
D
На сайте с 28.06.2008
Offline
1101
#6

Вот весь .htaccess


# Set some security parameters
Options All -ExecCGI -Indexes -Includes +FollowSymLinks
ServerSignature Off

# Turn on URL rewriting
RewriteEngine On

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

# Force UTF-8 encoding
AddDefaultCharset UTF-8


# Rewrite all other URLs to index.php/URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [L]
lonelywoolf
На сайте с 23.12.2013
Offline
151
#7

try_files $uri $uri/ /index.php/$request_uri;

прописывали ?

D
На сайте с 28.06.2008
Offline
1101
#8

Да, вот как было

location / {

try_files $uri $uri/ /index.php?$args;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php/$uri break;
}

}

так тоже дает 404

location / {

try_files $uri $uri/ /index.php/$request_uri;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php/$uri break;
}

}
lonelywoolf
На сайте с 23.12.2013
Offline
151
#9

location / {

try_files $uri $uri/ /index.php?$query_string;

}

D
На сайте с 28.06.2008
Offline
1101
#10
lonelywoolf:
location / {
try_files $uri $uri/ /index.php?$query_string;
}

это опять позволяет гулять по всему сайту - но инфа всегда только главной страницы

12

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий