Answer the question
In order to leave comments, you need to log in
How to set up routing in .htaccess, keeping 301 redirects?
Good day!
Please help me set up .htaccess:
There is a SPA on react using react-router-dom.
The hosting is Apache.
Previously, it was configured like this for the 301st redirect:
RewriteEngine On
RewriteCond %{ENV:HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^.*$ https://mysite.ru/$0 [L,R=301]
RewriteEngine On
RewriteCond %{ENV:HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
# Если по переданному пути в URI файлы или каталоги существуют то сервер вернет их содержимое
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Если существующих файлов не найдено то сервер вернет содержимое index.html
RewriteRule ^ index.html [L]
RewriteRule ^.*$ https://mysite.ru/$0 [L,R=301]
Answer the question
In order to leave comments, you need to log in
try to set up a 301 redirect in one line through the "Redirect" construct, and also swap the order of the rules in .htaccess (it may be that one rule overlaps another)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question