D
D
DodgeViper2017-02-10 07:15:36
htaccess
DodgeViper, 2017-02-10 07:15:36

Correct .htaccess setting. How to set up a redirect of all pages from http to https (there are additional conditions)?

The task is somewhat more difficult than it seems at first glance.

There is one domain HTTP://site1.com
There is a second domain HTTPS://site2.com which is redirected from HTTP://site1.com and from HTTP://site2.com by a plugin in CMS Wordpress.
The site has about 300 pages and they are constantly updated. Naturally, it is necessary that all pages from both HTTP://site1.com and HTTP://site2.com are automatically redirected to the secure version of the site, i.e. at https://site2.com .

Actually there is such a standard code

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress


I added a few changes there and added at the beginning:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]


It actually turned out like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress


With this code, all pages from HTTP://site2.com are redirected to HTTPS://site2.com without any problems . But from the pages of HTTP://site1.com , unfortunately, the redirect does not work. What can be thought up and added within the framework of this problem?
Thank you for your responses.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tester_toster, 2017-02-10
@tester_toster

Elementary:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

You take the relative name of the server. And jumps from test1 to test1

D
DodgeViper, 2017-02-10
@DodgeViper

Mmm... What then can be written instead of this code?

S
seotull, 2019-01-01
@seotull

Help
Created this .htaccess
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
Redirects to https on main and category but I have them on main pages http://site/category/page.html doesn't want

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question