T
T
Tupic1232021-08-19 20:41:38
htaccess
Tupic123, 2021-08-19 20:41:38

How to combine rules in htaccess?

Good afternoon! there is a file in which the following rules simultaneously work:
1) redirect from http to https
2) redirect from without www to www
3) redirect from without / at the end with / at the end
4) redirect from double // to
one redirect
611e96cb647dd932377687.jpeg
you need to add a redirect from double to single (without creating a chain of redirects
When I add a rule

RewriteCond %{REQUEST_URI} ^(.*)--(.*)$
RewriteRule . %1-%2 [R=301,L]

611e9758a93ef372577174.jpeg
the whole .htaccess chain is created
RewriteEngine On
RewriteCond %{REQUEST_URI} !\?
RewriteCond %{REQUEST_URI} !\&
RewriteCond %{REQUEST_URI} !\=
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://www.%1/$1/ [L,R=301]

RewriteCond %{REQUEST_URI} !\?
RewriteCond %{REQUEST_URI} !\&
RewriteCond %{REQUEST_URI} !\=
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{HTTP_HOST} ^([^www].*)$
RewriteRule ^(.*)$ https://www.%1/$1/ [L,R=301]

RewriteCond %{REQUEST_URI} !\?
RewriteCond %{REQUEST_URI} !\&
RewriteCond %{REQUEST_URI} !\=
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} ![^\/]$
RewriteCond %{HTTP_HOST} ^([^www].*)$
RewriteRule ^(.*)$ https://www.%1/$1 [L,R=301]


# DOUBLE / START
RewriteCond %{THE_REQUEST} //
RewriteRule .* /$0 [R=301,L]
# DOUBLE -- START
RewriteCond %{REQUEST_URI} ^(.*)--(.*)$
RewriteRule . %1-%2 [R=301,L]

Please tell me how to combine the rules so that a chain of redirects would not be created, and all redirects would occur simultaneously?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-08-19
@Tupic123

RewriteEngine On

RewriteCond %{REQUEST_URI} !/$  [OR]
RewriteCond %{THE_REQUEST} ^[^?]+(?://|--)
RewriteCond $1             ^(.*-)-(.*)$|(.*)
RewriteRule ^([^.]+?)/?$ https://www.soskin.com.ua/%1%2%3/ [R=301,L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.soskin.com.ua/$0 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question