htaccess 301 too many redirects help

kauhywka

Regular Member
Joined
Nov 20, 2014
Messages
261
Reaction score
51
I want to redirect from

www to no www (301)
http to https (301)
remove trailing slash from all pages
remove .html ending (301 to nonslash)
remove index.html if link is domain.com/index.html

I check some urls like
http://www.domain.com/dsadas/dasda/dasdas/dsa.html
and it gives 3 301 redirects before get to the page...
How I can combine all the thing work, that they will give me only one 301 redirect ALWAYS
PLZ HELP ME, I AM GOOGLING ALL DAY


now I am using that code

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ https://%{HTTP_HOST}%1 [R=301,L]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
</IfModule>
 
Back
Top