I
I
Ivan Ivanovich2019-01-23 14:20:11
htaccess
Ivan Ivanovich, 2019-01-23 14:20:11

How to combine multiple commands in htaccess?

Hello. How can I combine 2 commands into 1 file?
1. Remove .html and URLs

RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^\.]+)\.p?html?$ http://wot-shop.icu/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
2. Редирект на https
RewriteEngine On
RewriteCond %{HTTPS} =off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-01-23
@IwanQ

RewriteEngine On

RewriteCond %{THE_REQUEST} ^\S+\s+/([^.?]+)\.html
RewriteRule ^  https://wot-shop.icu/%1 [R=301,L]

RewriteCond %{HTTPS}     =off   [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule (.*)  https://wot-shop.icu/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]

V
Viktor Taran, 2019-01-23
@shambler81

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^\.]+)\.p?html?$ https://site.ru/wot-shop.icu/$1 [R=301,L]

But it's better not to do that. since there can be more redirects,
for example, with www
and this is already three, we’ll add a slash and delete it if it’s a file, and this is already five,
and five conditions in one will be unreadable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question