N
N
Nikita2015-09-10 16:03:10
htaccess
Nikita, 2015-09-10 16:03:10

How to write an htaccess rule?

Please tell me how to make a regular expression for my site.
Need a redirect.
from domain.ru/page1/1 to domain.ru/page1
from domain.ru/page1/2 to domain.ru/page1
from domain.ru/page1/25 to domain.ru/page1
from domain.ru/page1/25 /123 to domain.ru/page1
from domain.ru/page1/55/123 to domain.ru/page1
and so on... (all these pages are generated by WordPress on their own)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oaks, 2015-09-10
@nikita0509

Redirect from old static (cnc) page to new page:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.ваш_сайт\.ru$ [NC]
RewriteRule ^старая_страница $ новая_страница [R=301,L]

Redirect 301 /page1/1 domain.ru/page1
Redirect 301 /page1/2 domain.ru/page1
Redirect 301 /page1/25 domain.ru/page1
Redirect 301 /page1/25/23 domain.ru/page1

add_action( 'template_redirect', function() {
    if ( preg_match( '#^/subscribe/?$#i', $_SERVER['REQUEST_URI'] ) ) {
        wp_redirect( 'http://example.org/path/to/subscribe', 301 );
        exit;
    }
} );

D
Dmitry Samanev, 2015-09-10
@samanev

RewriteEngine On
RewriteBase /

## Два выражения выше уже должны быть в идеале ##
RewriteCond %{REQUEST_URI} ^(.*)(\/page1\/)(\S+)$
RewriteRule ^(.*)$ %2 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question