M
M
Mesuti2020-08-02 13:39:30
htaccess
Mesuti, 2020-08-02 13:39:30

How to keep the protection and add the correct redirect from www to non-www?

When going to the page www.site.ru/page/test
Redirect to site.ru/index.php/test
When going to the page www.site.ru
Redirect to site.ru/index.php with error 404

I understand the problem with part of the code where index.php is specified, but if you remove it, pages other than the main one give an error 404

How to keep the protection and add the correct redirect from www to non-www ?

RewriteEngine On

RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php 

#Редирект с www на без www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.site.ru$ [NC]
RewriteRule ^(.*)$ http://site.ru/$1 [R=301,L]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ross Alex, 2020-08-02
@Mesuti

RewriteEngine on
  # www to non-www
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
  # http to https
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php [L,QSA]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question