jkm

Рейтинг
120
Регистрация
20.02.2014
RewriteRule "^(.+?/)start http" /$1? [R=301,L]
kapec-master #:

Здраствуйте.

В логах вылезли страницы  с 404 ошибкой такого вида:

https: //site.ru/statiay/smarta_sumka _ belaya/www.tns-counter.ru/V13a****ar_ru/ru/UTF-8/tmsec=1021689_771724-3854277/7995618670995888828

https: //site.ru/statiay/ruchka_dilun _ fertyyne/www.tns-counter.ru/V13a****ar_ru/ru/UTF-8/tmsec=1021689_771724-3854277/6524891211361101840

https: //site.ru/statiay/depesha_dedilun _ yug/www.tns-counter.ru/V13a****ar_ru/ru/UTF-8/tmsec=1021689_771724-3854277/6743298988707820364


Подскажите, как сделать  301 редирект  (.htaccess) чтобы страницы  с 404 ошибкой перенаправлялись на оригинальные страницы без   www.tns-counter.ru/V13a****ar_ru/ru/UTF-8/tmsec=1021689_771724-3854277/7995618670995888828   :

https: //site.ru/statiay/smarta_sumka _ belaya/

https: //site.ru/statiay/ruchka_dilun _ fertyyne/

https: //site.ru/statiay/depesha_dedilun _ yug/

RewriteRule ^(.+/)www\.tns-counter\.ru /$1 [R=301,L]
Чтобы не две регулярки, а одной можно с помощью (?=...) заглянуть вперёд.
<a(?=[^>]*\sid="download")(?=[^>]*\shref="([^"]*)")

https://regex101.com/r/hXMzLh/1


Ещё вариант.

<a(?:\shref="([^"]*)"|\sid="download"()|[^>])++\2
https://regex101.com/r/hXMzLh/2
Xubart #:
 А реально не запрет, а редирект на другой сайт для них как то сделать? 

При срабатывании "Deny From" клиент получает ошибку 403.
Свою страницу ошибки можно указать с помощью ErrorDocument.

Note that when you specify an ErrorDocument that points to a remote URL (ie. anything with a method such as http in front of it), Apache HTTP Server will send a redirect to the client to tell it where to find the document, even if the document ends up being on the same server. This has several implications, the most important being that the client will not receive the original error status code, but instead will receive a redirect status code.


Т.е. если указать адрес с http:// или https://, то клиент получит не 403, а редирект 302.

ErrorDocument 403 http://domain/page
Sdrozdov :

такая конструкция:

Redirect 301 /stanki$ https://site.ru/stanki.php 

не срабатывает

С регулярками работает RedirectMatch

RedirectMatch 301 ^/stanki$ https://site.ru/stanki.php
webledi #:

Спасибо, в обоих случаях редиректит на /cat/29?cat_id=29

Значит где-то есть правило, которое добавляет этот "?cat_id=".

RewriteRule ^(cat/\d+)/  /$1 [R=301,L]

Это правило нужно поставить в начало файла .htaccess чтобы оно срабатывало раньше правила добавляющего "?cat_id=".

Перед проверкой не забыть сбросить кеш браузера.

RewriteRule ^(cat/\d+)/  /$1 [R=301,L]

Или

RedirectMatch 301 ^(/cat/\d+)/  $1
eavy #:

Как сделать редирект с одного домена на главную страницу другого?

То есть, что бы не ввели на oldsite.ru/fdsfsjfsjfs, чтобы перенаправляло на newsite.ru

RewriteCond %{HTTP_HOST} ^oldsite\.ru [NC]
RewriteRule ^ http://newsite.ru/ [R=301,L]
webinfo #:

Тогда уж так:

При использовании [F] незачем явно указывать ещё и [L]

https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_f

When using [F], an [L] is implied - that is, the response is returned immediately, and no further rules are evaluated.

Правило для блокировки нужно поставить выше правил ЧПУ вордпресса.

Всего: 749