How can I redirect my web pages using .htaccess, so old links are redirected to new ones?

I have links that have the old format

 www.mydomain.com/dir/this_my_page.html 

and my new script should be redirected to

 www.mydomain.com/newdir/this+my+page.htm 

What will I edit in my .htaccess file to make this possible? Can someone help me with the mod_rewrite htaccess function?

+3
source share
2 answers

. , htaccess (index.php), . URL- URL-, URL-, .

, , . , , .htaccess, , , !

.htaccess, index.php:

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

index.php , . Zend Framework MVC: http://framework.zend.com/manual/en/zend.controller.html

, .

+2

URL-, . ,

RedirectMatch ^/oldPath/(.*) http://www.example.com/newPath/$1

( URL-, ...)

, URL-, . uncool

RedirectMatch ^/dir/first_document.html /newdir/first+document.html
RedirectMatch ^/dir/second_document.html /newdir/second+document.html
RedirectMatch ^/dir/third_document.html /newdir/third+document.html

Regexp, , , ;)

, , 404, .

ErrorDocument 404 /redirect.php (or .jsp, .asp, .whatever)

script URL- / URL- URL- ( , , URL-. ( ) URL- . 301 URL.

+1

Source: https://habr.com/ru/post/1704314/


All Articles