K
K
Kirill Rezanov2020-10-28 14:02:38
htaccess
Kirill Rezanov, 2020-10-28 14:02:38

How to fix redirect error?

Trying to redirect old view urls: https://example.com/blog/ 2020/10/27 /alkogolnyj-delirij-simptomy-prichiny-lechenie/ to new view urls: https://example.com/blog/ article /alkogolnyj -delirij-simptomy-prichiny-treatment/.
Here is the code for the htaccess file:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
RewriteRule ^blog/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$ /blog/article/$1/? [L,R=301]
# END WordPress

The last rule works correctly, thanks to the curator of the #htaccess tag, helped in the last question, but here a problem looms, because. we redirect to another address, the server tries to find the page on its own, but does not find it and this piece works:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

Where at the end he pulls out index.php and redirects back to the old url, and so on with the new one. If you remove this line, then there will be no redirect back, but the server will give an error stating that the specified resource was not found on the server, what should I do in this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2020-10-28
@MayorPlay

I already answered in the last post read there
And here I gave you a couple of comments

# Включаем редиректы
RewriteEngine On
# по умолчанию путь будет начинаться с этой папки А не от корня физического дерева например /var/www/site.ru/web/upload
RewriteBase /
#  эмм ну мы тут удаляем индекс пхп, я бы еще добавил метод пост но  с вп не работал
RewriteRule ^index\.php$ - [L]

#видать от движка, но что-то кривое, по факту передаем в гет параметр все что перед files и admin
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

# если это файл 
RewriteCond %{REQUEST_FILENAME} -f [OR]
#  или директория OR меняет и на или
RewriteCond %{REQUEST_FILENAME} -d
#то  -
RewriteRule ^ - [L]

#не уверен что это не костыли поправьте меня кто с вп работал
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]

#  тоже странное правило
RewriteRule . index.php [L]
# читай в прошлом посте
RewriteRule ^blog/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$ /blog/article/$1/? [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question