F
F
filatovaa2020-10-24 23:05:52
PHP
filatovaa, 2020-10-24 23:05:52

How to organize a redirect on the site through .htaccess?

First of all, I remove the html extension:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]


When the user goes to the old address with the extension, I try to redirect it:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^ %1 [L,R=301]


After that, the site goes down, but page.html works instead of page.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vjacheslav Kanivetc, 2016-04-19
@Vjaka

In your scenario, rather, you need to use reshara through https://apiok.ru/wiki/pages/viewpage.action?pageId...

D
dodo512, 2020-10-24
@filatovaa

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.*)\.html$  /$1 [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^.]+)$ /$1.html [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question