Answer the question
In order to leave comments, you need to log in
How to redirect requests in htaccess?
Hello.
Help me figure out how to redirect non-existent urls (by mask) to one existing,
for example, redirect all addresses of the mysite.ru/katalog/* format to
mysite.ru/contacts Need a 301 redirect.
RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule ^(.+) webserverB.dom/$1 [R=301,L]
CMS Wordpress
Answer the question
In order to leave comments, you need to log in
If you need to redirect under the condition
if not 404
and
then Then .htaccess
will
not help you in principle, since you need to get the server response code before redirecting, which means that for any url on the site you will have to get the server response code. which in turn will greatly affect the performance of the site.
Therefore, this is not the right option
. The easiest way to solve the problem with the condition on 404
is to write rewrites in 404.php already in php, they are written easier and their cycles are less strange.
In this case, redirects will only work if the url is not found.
Now in your regular season
you messed up
firstly the sequence RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f
secondly the variable itself.
RewriteCond %{REQUEST_URI} ^(.*)/dir1/(.*)$
# если строка содержит /dir1/
RewriteRule ^(.*)$ %1/dir2/%2 [R=301,L]
#Перенаправить все урлы с начинающиеся с dir1 на dir2 с сохранением дальнейшей структуры URL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question