IsaevDimka
@IsaevDimka
маркетёр-аналитик, веб-разработчик

Как настроить редирект в Nginx с site.ru/index.php/slug/ на site.ru/slug/?

Добрый день, сайт не правильно проиндексировал из-за Laravel и не настроенного конфига Nginx.
Сейчас конфиг выглядит так:

server {
	server_name test.ru www.test.ru;
	ssl_certificate "/var/www/httpd-cert/www-root/test.ru_le1.crt";
	ssl_certificate_key "/var/www/httpd-cert/www-root/test.ru_le1.key";
	ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
	ssl_prefer_server_ciphers on;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	add_header Strict-Transport-Security "max-age=31536000;";
	ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
	charset UTF-8;
	index index.php index.html;
	disable_symlinks if_not_owner from=$root_path;
	include /etc/nginx/vhosts-includes/*.conf;
	include /etc/nginx/vhosts-resources/test.ru/*.conf;
	access_log /var/www/httpd-logs/test.ru.access.log;
	error_log /var/www/httpd-logs/test.ru.error.log notice;
	ssi on;
	set $root_path /var/www/www-root/data/www/test.ru/public;
	root $root_path;
	 if ($host ~* www\.(.*)) {
        set $host_without_www $1;
        rewrite ^(.*)$ https://$host_without_www$1 permanent;
    }

    if ($request_uri ~ "^(.*)index\.(?:php|html)") {
     return 301 $1;
    }
    if (!-f $request_filename) {
        rewrite [^/]$ $uri/ permanent;
    }
	listen 127.0.0.1:443 ssl http2;
	location / {
    try_files $uri $uri/ /index.php?$query_string;
		location ~ [^/]\.ph(p\d*|tml)$ {
			try_files /does_not_exists @php;
		}
		auth_basic "Access limited by ISPmanager";
		auth_basic_user_file /var/www/www-root/data/etc/access.test.ru.1B2M2Y8A.passwd;
	}
	location @php {
		fastcgi_index index.php;
		fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@test.ru";
		fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
		try_files $uri =404;
		include fastcgi_params;
	}
}


Этот редирект:
if ($request_uri ~ "^(.*)index\.(?:php|html)") {
     return 301 $1;
    }

убирает только index.php
нужен 301 редирект чтобы убирал после site.ru index.php

типа site.ru/index.php/asdasda → site.ru/asdasda/
site.ru/index.php/sasdad2 → site.ru/sasdad2/
  • Вопрос задан
  • 105 просмотров
Решения вопроса 1
vader666
@vader666
if ($request_uri ~ "^(.*)index\.(?:php|html)/(.*)") {
     return 301 $1$2;
    }
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
ivankomolin
@ivankomolin
location ~^ /index.php/slug {
    return 301 $host;
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы